Post Reply 
Conversion to Binary and IEEE-754 Binary
06-29-2020, 01:33 PM
Post: #3
RE: Conversion to Binary and IEEE-754 Binary
(06-27-2020 01:35 PM)Eddie W. Shore Wrote:  Bit 1 is the sign bit: 1 for negative numbers, 0 for positive numbers
The next eight bits is the exponent bit: The exponent bit has a bias of 127 ...
The last 23 bits consist of the mantissa.

Another interpretation is to think of exponents field and the mantissa overlapped on the imply bit.
For IEEE single, instead of bias of 127, do offset 126

Example: x = 2100 = 1.025390625 * 2^11 = 0b1.000001101 * 2^(0b10001001 - 126)

Code:
sign = 0
bexp =  1000100 1
mant =          10000011 01000000 00000000   ; upto 24 bits precision
SUM  = 01000101 00000011 01000000 00000000   ; bits for 2100.f

This has the advantage of extending conversion to sub-normal, without special treatment.
(i.e. when mantissa cannot converted to pattern 1.xxx ..., with bexp already reached 0)

Example: x = 1e-40f ≈ 71362.38 / 2^149. Since 71362 < 2^24, bexp = 0

→ bits = 71362 = 0b 00000000 00000001 00010110 11000010

gcc:1> unsigned u = 71362
gcc:2> G(*(float*) &u)
9.9999461011147596e-041
gcc:3> G(1e-40f)                     /* confirm */
9.9999461011147596e-041
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Conversion to Binary and IEEE-754 Binary - Albert Chan - 06-29-2020 01:33 PM



User(s) browsing this thread: 1 Guest(s)