开发者

Can't figure out how to convert this scientific # into IEEE 754

开发者 https://www.devze.com 2023-04-11 13:17 出处:网络
I can\'t seem to figure out how to convert 2 * 10^33 into IEEE 754 format. I find the sign bit to be 0

I can't seem to figure out how to convert 2 * 10^33 into IEEE 754 format.

I find the sign bit to be 0 I find the exponent to be 110 + bias (of 127) to be 0xED

But, the mantissa is just killing me.. I can't figure out why I keep getting 0 for this 开发者_StackOverflowpart.


You need the first 24 bits of 2*10^33. The first bit is always 1, and the remaining 23 bits form the last 23 bits of the IEEE-754 single-precision floating-point number.

Now, 2*10^33 has 110 binary digits, so it is too large to calculate exactly with most tools (calculators or programming languages). We can make things a little bit easier by noting that 2*10^33 = 2*(2*5)^33 = 2^34*5^33, so the first 24 bits of our number are the same as those of 5^33, which has only 76 bits.

We can further write:

5^33 = (2^7 - 3)^11
     = 2^77 - 11*3*2^70 + 55*9*2^63 - 165*27*2^56 + 330*81*2^49 
           - 462*243*2^42 + 462*729*2^35 - 330*2187*2^27 + ...
     = 2^53 * (2^24 - 33*2^17 + 495*2^10 - 4455*2^3 + 26730/2^4 
           - 112266/2^11 + 336798/2^18 - 721710/2^25 + ...)
     = 2^53 * (16777216 - 4325376 + 506880 - 35640 + 1670.625
           - 54.817... + 1.284... - 0.0215...)
     = 2^53 * 12924697.071
     = 2^53 * 110001010011011100011001b

where we rounded in the last step. So the stored part of the mantissa is 10001010011011100011001. Together with the information you already have, the result is:

0 11101101 10001010011011100011001

or in hex:

76C53719


If you want it done automatically, try this website. Type 2e33 into the top text box and hit the Rounded or Not Rounded buttons to get the answer.


If you type 2000000000000000000000000000000000 into my decimal/binary converter you will get

110001010011011100011001000100100011011001001100111000110000010101101100001010000000000000000000000000000000000

Rounded to 24 significant bits -- the number of bits in a float -- this is 110001010011011100011001 (the trailing 23 bits of this are the mantissa).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号