Binary
Numbers
A modern
electronic computer consists of millions of transistors which work
like switches. Each switch can be either OFF or ON. We can use the
two possible states of a switch to represent the numbers 0 and 1. By
combining many switches together we can represent larger numbers
using patterns of zeros and ones – such numbers are called binary
numbers, or base 2 numbers. Since humans have ten fingers and
thumbs they prefer to use decimal numbers, or base 10
numbers. You should know how to convert between binary numbers and
decimal numbers.
Consider the
decimal number 6247. We read this as ‘six thousand two
hundred forty seven’ and would understand that it is made up six
thousands, two hundreds, four tens and seven units. The position of
each digit tells us whether that digit represents thousands,
hundreds, tens or units. In your math class you should have learnt
that 1000= 103, 100= 102, ten = 101
and 1 = 100. Note that any number to the power of zero is
equal to one. So, to summarise, the meaning of each digit is
indicated in the table below.
|
6 |
2 |
4 |
7 |
|
103 |
102 |
101 |
100 |
|
Thousands |
Hundreds |
Tens |
Ones
(Units) |
Binary numbers
are interpreted in a similar way, but using base two instead of ten.
Consider the binary number 110101.
|
1 |
1 |
0 |
1 |
0 |
1 |
|
25 |
24 |
23 |
22 |
21 |
20 |
|
Thirty-twos |
Sixteens |
Eights |
Fours |
Twos |
Ones
(Units) |
We see that our
number is made up of a thirty-two, a sixteen, a four and a one, so
this binary number is equivalent to the decimal number 53
(32+16+4+1=53).
Converting Binary
numbers to decimal numbers
As explained
above, it is easy to convert a binary number to a decimal number by
considering the meaning of each digit (it’s best to start with the
right-most digit). For practice, try converting the binary number
10111 to decimal, then check your answer at the bottom of this page.
Of course, just
because a number is made up of ones and zeros does not automatically
mean it is a binary number. In the above text you knew that 10111
was a binary number because the text explicitly said so, but the
base of the number can also be indicated with a subscript like this
: 101112. Whereas the number 1011110 (base
10) can be read ‘ten thousand one hundred eleven’ the binary number
10111 should not be read like that for these binary digits or ‘bits’
do NOT represent thousands etc. The binary number 10111 should be
read ‘one zero one one one’.
Converting
decimal numbers to binary numbers
How would you
convert the decimal number 139 into binary form? The quickest
method is this:
1.
Divide the number by two using ‘integer division’ to give an answer
in the form of an integer plus a remainder.
2.
Keep dividing the integer results by two until there is nothing left
to divide (it’s best to do this in a vertical format as shown below)
3.
Now
read the remainders from bottom to top or allow the
column of remainders to ‘fall to the right'.
Example:
You can’t help
noticing that even a fairly small number like 95 looks horribly long
when written in binary. Working with such a long string of ones and
zeros it is very easy to make mistakes. To avoid working with binary
numbers we can always convert them to decimal, but that can be
rather tedious if you don’t have a scientific calculator handy. To
avoid having to work in binary or having to convert to between
binary and decimal, computer programmers often like to use
hexadecimal numbers, which you will read about next.
Hexadecimal
numbers
We note that ‘hex’
means ‘six’ and ‘deci’ means ‘ten’ so ‘hexadecimal’
means sixteen (6+10). Computer programmers like to work in
base 16 because it is very easy to convert binary numbers to
hexadecimal and back again. Unlike base 2 numbers which contain only
the digits 0 and 1, and decimal numbers which contain the digits
0-9, hexadecimal numbers consist of the digits 0-9 and the letters
A-F. The meaning of these letters is given in the table below:
|
Decimal |
Hexadecimal |
Binary |
|
Decimal |
Hexadecimal |
Binary |
|
0 |
0 |
0 |
|
8 |
8 |
1000 |
|
1 |
1 |
1 |
|
9 |
9 |
1001 |
|
2 |
2 |
10 |
|
10 |
A |
1010 |
|
3 |
3 |
11 |
|
11 |
B |
1011 |
|
4 |
4 |
100 |
|
12 |
C |
1100 |
|
5 |
5 |
101 |
|
13 |
D |
1101 |
|
6 |
6 |
110 |
|
14 |
E |
1110 |
|
7 |
7 |
111 |
|
15 |
F |
1111 |
To easily convert
binary numbers to hexadecimal (sometimes called simply ‘hex’) split
the binary number into groups of four binary digits (4 bits),
starting at the right end. Then use the table above to convert each
group into a single hexadecimal character. For example, consider the
binary number 1101101. Splitting this into groups of 4 bits
each we get 110/1101. Using the table above to convert each of these
binary numbers into hex we get 6D. We can write 11011012
= 6D16. Note that the rightmost digit in this hex
number represents units and the next digit represents sixteens, so
we have 6 sixteens and thirteen (D) units. So 6D16 =
(decimal) 6*16 + 13*1 = 109. (You probably already know that
computer programmers use an asterisk to represent multiplication.)
To convert a hex
number into binary just use the table above. For example B316
= 101100112. Note how the ‘3’ in the hex number was
expressed as the 4 bit number 0011 rather than the two bit number 11
shown in the table.
As already noted,
most scientific calculators can easily convert between decimal and
binary – such calculators can also convert to and from hex notation.
There’s more to
binary and hex than just conversions – regular operations such as
addition, subtraction and multiplication can be done in any of these
bases. For example, in binary, 1+1=10, and in hex C-A=2. Such
calculations can also be done on your scientific calculator.
You may have
noticed that your calculator can also work in base 8, called octal,
but that is less used than the other bases mentioned here and is
just mentioned in passing.
Now that you
know a bit about binary numbers you are ready to learn about
LOGIC GATES, some of the most important components in digital
electronic circuits. Click HERE
to continue.