Date: Thu, 1 Feb 1996 09:38:45 -0800 (GMT) From: Orlando Andico To: Armin Herzer cc: djgpp AT delorie DOT com Subject: Re: binary representation of floats Message-ID: MIME-Version: 1.0 On Wed, 31 Jan 1996, Armin Herzer wrote: > What I want to do is to get the binary representation of a float > or double (the way these numbers are stored in memory). How can I obtain > them? How do I modify them? Is there a documentation from which I can see > how the format of these binary represetations on PC's (and in DJGPP) is. I'm sure you can find the description of IEEE floating-point numbers in any good computer architecture book, though I'm not sure how FP numbers are handled in DJGPP as the IEEE 754 standard specifies only 32-bit and 64-bit floating point representations while the 80x87 math coprocessors (and DJGPP _always_ uses one, emulator or no) specify an 80-bit floating point format... maybe DJ will have something more to say about this. Anyway, (as I remember) the basic 32-bit IEEE 754 FP number stores the sign bit in the leftmost bit, followed by 8 bits of normalized exponent. Since 8 bits can handle 0..255, exponents < 0 are normalized by adding 127, so the range of _binary_ exponents allowed is -127..+128. The remaining 23 bits are the mantissa, with an implied 1 (i.e. the mantissa is always > 1). The Intel architecture stores stuff in a little-endian fashion, so your IEEE number in 4321 format will probably come out as 1234... what you could do is convert some FP number to IEEE 754 format by hand, store it in memory, then dump the 4(8) bytes and analyze them to determine the way DJGPP stores the bytes. Then again, maybe it uses the 80x87 80-bit format partway through... Anyways, once you got the binary representation, you could have a char * pointing to your float and use the ordinary bitwise manipulations to mess with it. ------------------------------------------------------------------------------ | Orlando A. Andico "I have no concept of time, other than | | oandico AT eee DOT upd DOT edu DOT ph it is flying." -- Alanis Morissette | ------------------------------------------------------------------------------