Re: Please HELP!!!!! [message #4934 is a reply to message #4866] |
Wed, 23 August 1995 00:00   |
pjclinch
Messages: 27 Registered: May 1993
|
Junior Member |
|
|
Phil (phil@peace.med.ohio-state.edu) 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.
: 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.
First of all, the format will depend on your system. VAXen use a
unique floating point format, I think, but other than that it's probably
IEEE 753-1985, which is the main standard.
format for a 32 bit float is:
bit 31: sign bit, 1 -> negative, 0 -> positive
bits 30-23: exponent
bits 22-0: significand
the problem interpreting these is usually in the significand, which is,
not very intuitively at first sight, a binary fraction greater or equal
to 1 and less than 2. I think (but can't be totally sure offhand) that
all the significand bits set at 0 is equivalent to an actual value of 1,
while all set at 1 is not quite 2, with fractional points in between.
the other fun bit is the exponent, which you get by subtracting a bias
value of 127. This allows you to get negative exponents, so an actual
bit value of 130 in bits 30->23 would mean an exponent of 3 for the
actual number represented.
Have fun...,
Pete.
--
Peter Clinch Dundee University & Teaching Hospitals NHS Trust
Tel 44 1382 660111 x 3637 Medical Physics, Ninewells Hospital
Fax 44 1382 640177 Dundee DD1 9SY Scotland UK
net p.j.clinch@dundee.ac.uk http://www.dundee.ac.uk/MedPhys/
|
|
|