Hi !!
This is very hard for me to describe in english. But i will try:
I have a binary file, it is build via a programm, written in pascal. I must read the datas of the binary file into a mysql-db and must find a way to create a working binary file. The import is no problem. But the way back... I've problems to write a ... i don't know the word in english (1.2, 35.23, 0.2,...<-- u know what i mean?) into a binary string.
I've solved the problem for importing with this function. It was given me as an demo in a tlc-script.
function convreal ($sixbytes) {
$data = @unpack("cPOW/c4MANT/cMANTnull",$sixbytes);
if($data) {
$real = pow(2,($data[POW]+0x100)%0x100-129);
if ($data[MANTnull]<0) {
$real = -$real;
$data[MANTnull] = abs($data[MANTnull]);
}
$div = $real/128.0;
$data[MANT5] = $data[MANTnull];
for ($j = 5; $j>=1; $j--) {
$real = $real+(($data["MANT".$j]+0x100)%0x100)*$div;
$div = $div/256.0;
}
$real = round($real*100)/100.0;
}
else {
$real = 0;
}
return $real;
}
the function gets 6 Bytes as argument an split them with the unpack-function into 6 Values. I've made some examples:
$data[POW] | $data[MANT1] | $data[MANT2] | $data[MANT3] | $data[MANT4] | $data[MANTnull] |
-----------------------------------------------------------------------------------------------------
-127 | 0 | 0 | 0 | 0 | 0 | = 1
127 | 51 | 51 | 51 | 51 | 51 | = 0.35
-127 | -51 | -52 | -52 | -52 | 12 | = 1.1
127 | 0 | 0 | 0 | 0 | 0 | = 0.25
127 | -61 | -11 | 40 | 92 | 15 | = 0.28
-128 | 102 | 102 | 102 | 102 | 102 | = 0.9
-128 | 0 | 0 | 0 | 0 | 0 | = 0.5
...ok... can anybody help me with this? Or has anybody material how pascal writes this kind of numbers into binary string? Every help would be great!
Thanx
Stuck