FWNX - 补码 反码 负数 在电脑中的存放规则- 边界值

来源:互联网 发布:美食甜品软件 编辑:程序博客网 时间:2024/06/05 19:12

以 32 bit int 为例 

最高位是1 则代表是负数; 0 则代表是正数;

最大的正数 

二级制形式

0111 1111 1111 1111  1111 1111 1111 1111 

hex:

0x 7 f f f f f f f

       decimal :

2^31 - 1 ; 

this is a Geometric sequence

2^0 + 2^1 +……+2^31

                 Sn = a1(1-q^n)/1-q

in this case; n = 31; q = 2; a1 = 2^0 = 1;so

Sn = q^31 -1 = 2^31 -1; 

Sn = 2147483647

the small negative integer

in binary :

1000 0000 0000 0000 0000 0000 0000 0000

hex :

0x80000000

decimal : 

firstly this is a neg ; 

negate the numbers behind 1; make the signal bit as 0

it becomes 

0111 1111 1111 1111 1111 1111 1111 1111

plus 1 

1000 0000 0000 0000 0000 0000 0000 0000

then this is 2^31 and a negative so it is 

-2^31

this is -2147483648

0 0
原创粉丝点击