Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
BINARY AND HEX<br />
Binary and Hex<br />
The Arithmetic of Computing<br />
by<br />
Carol Brooksbank<br />
It might seem odd to start an article<br />
about binary and hex by<br />
talking about decimal arithmetic,<br />
but the processes involved<br />
in all three systems are the<br />
same. Only the number of digits<br />
used is different. The trouble is<br />
that we are all so expert in using<br />
decimal counting that we no<br />
longer think about the<br />
mechanics of what we are doing.<br />
Almost everyone can count<br />
from 1 to 1 00 without worrying<br />
about the processes involved,<br />
and even someone with no head<br />
for figures can add 1 to 99 and<br />
get the right answer without a<br />
second thought about what<br />
they did. They just know how to<br />
doit. But if you understand what<br />
is happening when you count in<br />
decimal, you are half way to<br />
becoming fluent in binary and<br />
hex, so t am going to analyse<br />
decimal counting. Please don't<br />
skip this bit just because it<br />
seems very elementary. You will<br />
get to grips with the other<br />
systems much more easily if you<br />
read on.<br />
Decimal<br />
In decimal arithmetic, there are<br />
1 0 digits which are always used<br />
in the same order when counting:<br />
0123456789<br />
Because of the need to use<br />
numbers higher than 9, a col<br />
umn system is used, Imagine the<br />
digits arranged in a vertical column.<br />
When 9 is reached, we<br />
have run out of digits, so a second<br />
column is brought in to the<br />
left of the first one, and this new<br />
column is assumed to hold 0. To<br />
progress beyond 9,1 is added to<br />
the amount in the new column,<br />
and the original one is returned<br />
to 0 . This gives the number we<br />
call ten.<br />
0<br />
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
09<br />
10<br />
You can then count on, until you<br />
reach 9 again in the right hand<br />
column, when you repeat the<br />
process, adding 1 to the left column<br />
and returning the right one<br />
toO.<br />
19<br />
20<br />
This process can continue until<br />
99 is reached, when you need to<br />
bring in another column to the<br />
left.<br />
98<br />
099<br />
Now, as before, you add 1 to the<br />
leftmost column and return all<br />
the others to 0.<br />
099<br />
100<br />
You can go on like this for as<br />
long as you need. Every time you<br />
add 1 to a column, you return all<br />
those to the right of it to 0, and<br />
every time all the columns in use<br />
reach 9, you bring in another to<br />
the left. In this way, any<br />
number, as big or small as you<br />
wish, can be expressed.<br />
Because there are 1 0 digits in<br />
use, each new column is worth<br />
1 0 times the one on its right.<br />
The number 548,672 is actually<br />
made up like this:<br />
100,000 x 5 500,000 +<br />
10,000 x 4 = 40.000 +<br />
1,000 x 8 = 8,000 +<br />
100 x 6 = 600 +<br />
10x2= 20 +<br />
1x7= 7<br />
TOTAL 546827<br />
This columns system is exactly<br />
the same in binary and hex, so<br />
the only new factor is the<br />
number of digits.<br />
Binary<br />
In binary arithmetic, there are<br />
only 2 digits: 0 and 1 .As before,<br />
you count in one column until<br />
you run out of digits, when you<br />
introduce a new one to the left.<br />
The difference is that you run<br />
out of digits much more quickly<br />
in binary.<br />
Binary Decimal<br />
0 0<br />
01 1<br />
10 2<br />
The number reached at this<br />
point in binary, 10, is not ten. It<br />
is one-oh binary. Ten is a name<br />
reserved for one-oh decimal,<br />
and in order to avoid any confusion,<br />
you should always think of<br />
the binary numbers as one-oh<br />
binary, one-one binary and so<br />
on.<br />
You carry on counting in<br />
binary in exactly the same way<br />
as in decimal, introducing new<br />
columns as they are needed.<br />
11 3<br />
100 4<br />
101 5<br />
110 6<br />
111 7<br />
1000 8<br />
You will see by now the great<br />
disadvantage of binary. With so<br />
few digits the numbers quickly<br />
become longer, so that the<br />
number expressed as '8' in<br />
decimal is a four figure number<br />
in binary. In fact, because the<br />
numbers are long and in order to<br />
reduce confusion between<br />
systems, it is usual to express all<br />
binary numbers up to 255<br />
decimal as eight figure numbers:<br />
8 decimal BIN 00001000<br />
255 decimal - BIN 111 11111<br />
As there are ohly 2 digits, each<br />
column in binary is worth twice<br />
the column to its right.<br />
128 64 32 16 8 4 2 1<br />
1 1 1 1 1 1 1 1<br />
To convert a BIN number to<br />
decimal, you work as follows:<br />
BIN 1 111 1 11 1 -<br />
128 X 1 =<br />
64 X 1 =<br />
32 X 1<br />
128 +<br />
64 +<br />
32 +<br />
16 X 1 = 16 +<br />
8 X 1 = 8 +<br />
4 X 1 = 4 +<br />
2 X 1 = 2<br />
1 X 1 = 1 +<br />
TOTAL 255<br />
In binary, just as in decimal, you<br />
can introduce as many columns<br />
as you need to express a number<br />
of any size. Take the decimal<br />
number 1 2345, for instance. In<br />
binary, this is<br />
001 10000001 1 1001<br />
Since binary is such a cumber<br />
some system with long awkward<br />
numbers, what use is it?<br />
Well, in ordinary everyday life,<br />
not a lot, but in the world of electronics,<br />
it has one great advantage,<br />
Because there are only<br />
two digits, it is possible to express<br />
the numbers electronical-<br />
iy-<br />
Imagine that you have a bank<br />
of eight electric wires, each<br />
equipped with a switch. If you<br />
switched the switches so that 0<br />
was represented by an inert wire<br />
(switch off), and 1 was<br />
represented by a live wire<br />
(switch on), you could express<br />
the binary form of any number<br />
between 0 and 255 decimal.<br />
Put very crudely, this is what<br />
happens inside your computer.<br />
You can think of each address in<br />
your computer's memory as a<br />
minute bank of 8 electric wires<br />
and switches. When you poke a<br />
number into an address, the<br />
switches are manipulated so<br />
that the pattern represents the<br />
binary form of your number. The<br />
particular combination of live<br />
and inert wires causes the computer<br />
to perform some operation,<br />
It is beyond the scope of<br />
this article to go any further into<br />
the workings of the computer,<br />
but I want you to understand the<br />
importance of binary arithmetic<br />
54 ZX COMPUTING DECEMBER/JANUARY 1985