Re: Please HELP!!!!! [message #4948 is a reply to message #4866] |
Tue, 22 August 1995 00:00  |
Mike Mathews
Messages: 7 Registered: May 1995
|
Junior Member |
|
|
phil@peace.med.ohio-state.edu (Phil) wrote:
> Howdy,
>
> I have a problem that is only loosely related to IDL that I hope one
> of you can help me out. I want to take the bytes from a 32-bit
> floating point number and determine the floating point value of it. I
> can do this in IDL by the following:
>
> IDL>a = bytarr(4)
> IDL>openw,1,'temp'
> IDL>writeu,1,160.0
> IDL>close,1
> IDL>openr,1,'temp'
> IDL>readu,1,a
> IDL>close,1
> IDL>print,float(a,0)
> 160.0
> IDL>print,a
> 67 32 0 0
>
> Now, here is the problem. I'm trying to get the same answer by hand
> and can't seem to do it. I have been doing all sorts of interations
> to get the sign, exponent and mantissa for this and nothing seems to
> work. I know this is simple, but I just seem to be missing something.
> Could one of you people out there humble me and show me what I am
> doing wrong.
>
Try the following for the 32bits
s eeeeeeee fffffffffffffffffffffff
msb lsb msb lsb
l/msb is least/most significant bit
if 0 < e < 255 then v = (-1)^s * [2^(e-127)] * (1.f)
if e = 0 and f <> 0 then v = (-1)^s * [2^(-126) ] * (0.f)
if e = 0 and f = 0 then v = (-1)^s * 0
if e = 255 and f = 0 then v = (-1)^s * inf
if e = 255 and f <> 0 then v = NaN (not a number)
I haven't check your numbers but I hope this helps
Mike
--------------- mailto:fskmjm@pukfsk.puk.ac.za --------------------
Antarctic Workgroup Potchefstroom University
Physics Department South Africa
--------------- http://www.puk.ac.za/fskdocs/ --------------------
|
|
|