Re: Float procedure [message #13742] |
Wed, 02 December 1998 00:00  |
eddie haskell
Messages: 29 Registered: September 1998
|
Junior Member |
|
|
Charlie Solomon wrote:
>
> Can anyone shed some light on how this byte array is converted into a
> floating point number?
> two_words = bytarr(4)
> two_words = [244, 232, 165, 64]
first off, the second assignment statement makes two_words an intarr,
not a bytarr as intended.
to keep two_words as a bytarr do something like:
two_words = byte([244,232,165,64]) -or maybe-
two_words[*] = [244, 232, 165, 64]
> IDL> print, float(two_words, 0)
> 2.13062e-038
when you use the offset in the float procedure, IDL takes the first 32
bits it finds from the point
specified in the offset, in this case, the beginning of the array.
you can see this if you look at the binary representation of the numbers
(i.e. using kevin ivory's
binary program):
IDL> print,binary(float(two_words,0))
0 0 0 0 0 0 0 0 1 1 1 1 0 1 0 0
0 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0
IDL> print,binary(244),binary(232)
0 0 0 0 0 0 0 0 1 1 1 1 0 1 0 0
0 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0
as to the difference between machines, that could be a big/little endian
thing but i really don't
know for sure (can anybody verify this?)
cheers,
eddie
----- ---- --- ---- --- --- --- --- -- -- -- - - - -
|\ A. G. Edward Haskell
|\ Center for Coastal Physical Oceanography
|\ Old Dominion University, Norfolk VA 23529
|\ Voice 757.683.4816 Fax 757.683.5550
|\ e-mail haskell@ccpo.odu.edu
----- ---- --- ---- --- --- --- --- -- -- -- - - - -
|
|
|