Re: From Bytes to Doubles, etc. [message #12022 is a reply to message #11986] |
Wed, 17 June 1998 00:00  |
csaute3
Messages: 10 Registered: March 1998
|
Junior Member |
|
|
Justin,
You posted asking how to convert binary data
back to the original numbers. you said there are only a few numbers
that you want to convert and you know where they exist in the array.
This is what I do:
; getblock in function which reads the data and returns a byte array
data = getblock(arg1, arg2)
; to convert to long where 0 is my offset in the byte array
number = long(data, 0)
; to convert to float where 16 is my offset in the byte array
a = float(data, 16)
; to convert a structure where 20 is my offset in the byte array
; to the beginning of the structure
structure = {gridstruct, usage:long(0), r:float(0.0), z:float(0.0)}
grid = {gridstruct}
grid.usage = long(data, 20)
grid.r = float(data, 24)
grid.z = float(data, 28)
; to convert a string where 32 is my offset in the byte array
; and my string is length 20 characters. this must be known.
; i often store the length as a long in my byte array and read
; it first.
name = ''
namelength = 20 ; number of characters
tmp = bytarr(namelength)
tmp = data(32:32+namelength-1)
name = string(tmp)
I hope this helps. Look up in the IDL help about long, float, double.
Cathy
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
|
|
|