Binary Numbers
"There are 10 kinds of people in the world - those who understand binary and those who don't."
Positional Notation
Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Value | 107 | 106 | 105 | 104 | 103 | 102 | 101 | 100 |
... | ... | ... | 10,000 | 1,000 | 100 | 10 | 1 |
Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Value | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Value | 167 | 166 | 165 | 164 | 163 | 162 | 161 | 160 |
... | ... | ... | 65536 | 4096 | 256 | 16 | 1 |
How many digits?
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Hexadecimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
Hexadecimal is a convenient shorthand for Binary
BA16 = 1011 10102 = 18610
1 byte | = | 8 binary digits | = | 2 hexadecimal digits | ||
1 word | = | 2 bytes | = | 16 binary digits | = | 4 hexadecimal digits |
1 long word | = | 4 bytes | = | 32 binary digits | = | 8 hexadecimal digits |
Representing Data
Restricted by a finite number of bits - byte, word, long word
Unsigned and Signed Integers
If only interested in natural numbers, can represent natural numbers by their binary value within the computer. Most computer provide some support for representing and manipulating unsigned integers.
Representation of signed integers is more important.
Several possibilities:
In any representation, desirable properties are
Sign & Magnitude
Bit Pattern | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Unsigned | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Sign & Magnitude | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −0 | −1 | −2 | −3 | −4 | −5 | −6 | −7 |
One's Complement
Bit Pattern | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Unsigned | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Sign & Magnitude | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −0 | −1 | −2 | −3 | −4 | −5 | −6 | −7 |
One's Complement | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −7 | −6 | −5 | −4 | −3 | −2 | −1 | −0 |
Two's Complement
Bit Pattern | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Unsigned | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Sign & Magnitude | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −0 | −1 | −2 | −3 | −4 | −5 | −6 | −7 |
One's Complement | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −7 | −6 | −5 | −4 | −3 | −2 | −1 | −0 |
Two's Complement | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −8 | −7 | −6 | −5 | −4 | −3 | −2 | −1 |
Example: 1011 to decimal = −[0100 + 1] = −0101 = −5
Example: 1011 = −1000 + 0011 = −23 + 21 + 20 = −8 + 3 = −5
Example: −3 = −[0011] => 0010 => 1101
Example: −3 = −8 + 5 => 1000 + 101 => 1101
Excess-n (Bias-n)
Bit Pattern | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Unsigned | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Sign & Magnitude | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −0 | −1 | −2 | −3 | −4 | −5 | −6 | −7 |
One's Complement | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −7 | −6 | −5 | −4 | −3 | −2 | −1 | −0 |
Two's Complement | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −8 | −7 | −6 | −5 | −4 | −3 | −2 | −1 |
Excess-8 | −8 | −7 | −6 | −5 | −4 | −3 | −2 | −1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
Binary-Coded Decimal (BCD)
Bit Pattern | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Unsigned | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Sign & Magnitude | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −0 | −1 | −2 | −3 | −4 | −5 | −6 | −7 |
One's Complement | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −7 | −6 | −5 | −4 | −3 | −2 | −1 | −0 |
Two's Complement | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | −8 | −7 | −6 | −5 | −4 | −3 | −2 | −1 |
Excess-8 | −8 | −7 | −6 | −5 | −4 | −3 | −2 | −1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
BCD | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | - | - | - | - | - | - |
last updated: 19-Oct-06 Ian Harries <ih@doc.ic.ac.uk>