简体   繁体   English

浮点二进制表示

[英]Floating point binary representation

I have a problem understading a floating point representation(Two's placement-sign mantissa exponent), could you check, am I doing right? 我对浮点表示法有一个疑问(Two的放置符号尾数指数),可以检查一下,我做对了吗?

-1/7

-1*1/7*2^0=-1*4/7*2^1=-1*4/7*2^2=-1*8/7*2^3

so in binary itd be like: 所以在二进制itd中是这样的:

1 00000011 1.001 001 001 001 001 001 001

1/1357
1*1/1357*2^0=1*2048/1357*2^-11
0 | 11110101 | 1.100 000 100...

-205,34
1,60422*2^7
1| 0000011

1 | ...

My main problem is when to know the exponent is negative, could you give me any tips? 我的主要问题是何时知道指数为负,您能给我一些提示吗?

I assume you're talking about float (ie IEEE754 binary32 )? 我假设您在谈论float (即IEEE754 binary32 )?

In binary, the exact value is 在二进制中,确切值是

-1/7 = -1.001001001001001001001001001… 2 × 2 −3 -1/7 = -1.001001001001001001001001001… 2 ×2 −3

Firstly, the exponent is in the range [-126,12], so we don't need to worry about underflow or overflow. 首先,指数在[-126,12]范围内,因此我们不必担心下溢或上溢。

We then round the significand to 24 bits: 然后,将有效位数四舍五入为24位:

-1.00100100100100100100101 2 × 2 −3 -1.00100100100100100100101 2 ×2 -3

(note the last bit of the significand is rounded up) (请注意,有效位的最后一位被四舍五入)

We rewrite the exponent in it's biased form (the exponent bias is 127): 我们以有偏形式重写指数(指数偏差为127):

-1.00100100100100100100101 2 × 2 124−127 -1.00100100100100100100101 2 ×2 124−127

Then we can read off the bit pattern directly: 然后我们可以直接读取位模式:

1|01111100|00100100100100100100101

where: 哪里:

  1. the sign is negative, so the sign bit is 1 (1 bit) 符号为负,因此符号位为1 (1位)
  2. 124 in binary 01111100 (8 bits) 124 in binary 01111100 (8 bits)
  3. we drop the implicit leading 1 from the significand (23 bits) 我们从有效位(23位)中删除隐含的前导1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM