Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

retrieving values in binary files

 [1/6] from: hugues:moisy:geosignal at: 1-Oct-2002 16:08


Hello Rebolers, I'm beginner in Rebol, and I'm trying to retrive values in binary files. These files contain geographical coordinates, stores as doubles (4 or 8 bytes big-endian). I can easily retrieve integer values stored in big-endian or little-endian format, but an don't know how to retrieve floating values stored as floats or doubles in binary format (big-endian or little-endian). Any one do know how thoses values are implmented ? Thanks a lot. Hugues.

 [2/6] from: greggirwin:mindspring at: 1-Oct-2002 10:27


Hi Hugues, << I'm beginner in Rebol, and I'm trying to retrive values in binary files. These files contain geographical coordinates, stores as doubles (4 or 8 bytes big-endian). I can easily retrieve integer values stored in big-endian or little-endian format, but an don't know how to retrieve floating values stored as floats or doubles in binary format (big-endian or little-endian). Any one do know how thoses values are implmented ? >> I've done integers as well, but not decimals. They're implemented as IEEE 64 bit doubles, but the few things I tried this morning didn't work for getting them out of a file. I.e. to decimal! didn't like them. Maybe submit feeback to RT on it. I don't think we want to be filtering bits in REBOL to do it. :) --Gregg

 [3/6] from: larry:ecotope at: 1-Oct-2002 10:16


Hi Hugues, You can find funtions to read and write binary IEEE doubles in the package decimal.r written by Eric Long and myself. http://www.nwlink.com/~ecotope1/reb/decimal.r Cheers Larry ----- Original Message ----- From: "Hugues Moisy" <[hugues--moisy--geosignal--fr]> To: "Rebol List" <[rebol-list--rebol--com]> Sent: Tuesday, October 01, 2002 7:08 AM Subject: [REBOL] retrieving values in binary files
> Hello Rebolers, > > I'm beginner in Rebol, and I'm trying to retrive values in binary files.
These files contain geographical coordinates, stores as doubles (4 or 8 bytes big-endian).
> I can easily retrieve integer values stored in big-endian or little-endian
format, but an don't know how to retrieve floating values stored as floats or doubles in binary format (big-endian or little-endian).

 [4/6] from: rotenca:telvia:it at: 1-Oct-2002 19:21


Hi Hugues,
> I can easily retrieve integer values stored in big-endian or little-endian
format, but an don't know how to retrieve floating values stored as floats or doubles in binary format (big-endian or little-endian). I do not know if this can help, but given a 4/8 byte binary read from a file which represent a float/double IEEEE number, you could do: float: make struct! [num [float]] none change third float #{0000C841} float/num ; == 25 double: make struct! [num [double]] none change third double #{0000000000003940} print double/num ;==25 For big/little endian you should reverse binary before using it. --- Ciao Romano

 [5/6] from: g:santilli:tiscalinet:it at: 1-Oct-2002 20:08


Hi Hugues, On Tuesday, October 1, 2002, 4:08:44 PM, you wrote: HM> I can easily retrieve integer values stored in big-endian or little-endian format, HM> but an don't know how to retrieve floating values stored as floats or doubles HM> in binary format (big-endian or HM> little-endian). I think the internal format used by REBOL is platform dependent. However, if you happen to have your values in the same format used by REBOL you can convert them very quickly with something like:
>> s: make struct! [num [decimal!]] [0.0] >> third s
== #{0000000000000000}
>> s/num: 1.0
== 1
>> third s
== #{000000000000F03F}
>> s/num: 150.3
== 150.3
>> third s
== #{9A99999999C96240}
>> change third s #{000000000000F03F}
== #{}
>> s/num
== 1 This should also give you hints on how DECIMAL! is implemented on your platform. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [6/6] from: hugues:moisy:geosignal at: 2-Oct-2002 10:01


Hy Larry, Romano, Greg & Gabrielle, Thanks. I have downloaded your script, and I'll test it this night. Regards. :) Hugues