2011年6月10日 星期五

二進位正負表示


-2的表示法:


Step 1:
找出+2的表示法: 0000 0010

Step 2:
invert all bits.
0000 0010 -> 1111 1101

Step 3:
加上1.
1111 1101 + 1 = 1111 1110

1111 1110 即為 -2 的表示法。






(+2) + (-2) = 0:


0000 0010 + 1111 1110 = 1 0000 0000

0000 0010
+ 1111 1110
---------------
1 0000 0000

bit 0-bit 7 為 0000 0000
bit 8 進位為 1

只看bit0-bit7
所以 0000 0000 = 0






1111 1110 代表十進位數值為何?

Step 1:
1111 1110 -1 = 1111 1101

Step 2:
invert all bits.
1111 1101 -> 0000 0010 -> 2