|
|
Using the unsigned binary number system we know:
1 is 2^0 = 1
10 is 2^1 = 2
100 is 2^2 = 4
...
1000 0000 is 2^7 = 128
The place values for n=8 bits UNSIGNED is:
128 64 32 16 8 4 2 1
--- -- -- -- - - - -
2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0
SO: 1 0 0 0 0 0 1 0 = 128 + 2 = 130
To express negative numbers, the scheme of the binary positional number system is simply changed slightly - with a large impact. Using n bits, the nth bit is simply changed from positive to negative. The place values for n=8 bits SIGNED is:
-128 64 32 16 8 4 2 1
--- -- -- -- - - - -
2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0
SO: 1 0 0 0 0 0 1 0 = -128 + 2 = -126
This scheme of representation is arrived at by taking the two's complement of a number - flipping the bits and adding one - as a way of negating the number. 0000 1111 = 15 = 8 + 4 + 2 + 1 1111 0001 = -15 (flip all bits and add one) 1111 0001 = -15 = -128 + 64 + 32 + 16 + 1 The high bit, (nth it) becomes the "sign bit" only because, if set, it indicates the number must be negative - it actually represents -2^(n-1).
n > 8 bits ========== Nothing changes - an elegant scheme. If n = 16, |