Binary Numbers

"There are 10 kinds of people in the world - those who understand binary and those who don't."

Positional Notation


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


Representing Data


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


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 - - - - - -


[ Index ]

last updated: 19-Oct-06 Ian Harries <ih@doc.ic.ac.uk>