COMPUTER BASICS: HEXADECIMAL AND BINARY NUMBERS.....................Rick Ryall

     Hexadecimal  and binary are two words that appear frequently in  computer
magazines, machine manuals, and other computer related literature.  Most often
the text uses the terms assuming that you, the reader, already know what is
meant by them,  and there is a good chance that you don't. This article will
explain  a  little bit about what is meant by hexadecimal and binary  numbers,
and  also how you can convert them into something that you understand (if  you
are willing to do a little bit of work).   If it appears to be going too  fast
for  you,  read it through once,  not understanding what you are reading,  and
then come back to it again later.  Often this will help things sink in.

     Before  launching into the subject,  it is necessary to review  something
with which we are all familiar and use quite often,  but probably don't
remember how it works:  our numbering system.  Our numbering system is based
on ten digits (0-9),  undoubtedly because most of us have ten extensions
sticking out of  our hands that are useful for counting (If our prehistoric
ancestors  had been born with only 8 fingers and thumbs,  I bet our numbering
system would be quite different).  It is called the base 10 numbering system,
and 10 is called the "base".   This means, in terms with which we are
familiar, we start counting  at 0 and continue until we reach 9,  then we go
to 10 and count until  we reach 19,  then we go to 20,  and so on.    We
always count ten numbers in the far  right  column  before any of the columns
on the left  change.   Notice  a relationship?   We count ten numbers and a
column to the left  changes.    The base for our numbering system is ten.  The
base is the key.  Remember this, it is important.

     If  we look at some larger numbers,  we will notice something interesting
about them.   Take,  for instance,  the number 2,379.  What does the "2" stand
for?   It  stands for 2 thousands,  in the same way that the "3" stands for  3
hundreds,  the "7" for 7 tens,  and the "9" for 9 ones.   If you can  remember
back  to  grammar school,  we called these columns the ones column,  the  tens
column,  the hundreds column, and the thousands column.  The interesting thing
is  that each column is ten times as big in value as the column to  its  right
and that ten is the base.  The base is the key.  Another way of looking at the
number  2,379 is that it is equal to (2 x 1000) + (3 x 100) + (7 x 10) + (1  x
1) which in turn is equal to 2000 + 300 + 70 + 9.

     Now let's look at binary numbers.  Computers do not have hands or fingers
and  they  are not the least bit intelligent,  so they count in a very  simple
manner.   They count to 1.  That's right, the machines that baffle us with the
speed  and accuracy with which they can perform mathematical computations  are
only  capable of counting to 1 (we're not that much better,  since  we  really
only  count from 0 to 9).   Computers use base 2 (there are only two  counting
numbers,  0 and 1) when they count,  hence the name "binary".  This means that
they start counting at 0,  continue up to 1,  and then what?  What comes after
1?   Well,  10 comes after 1, but you have to remember that it is 10 base two,
not 10 base ten.   If you add one more to 10 (in base two) you get 11.  If you
add one more to that you get 100 (base two).  Let's see why.

     Remember how each column in our numbering system is ten times as large in
value  as the column to the right?   It is the same in base two,  except  each
column  is  two times as large as the column on its  right.   As  an  example,
consider the number 10010110 in base two.   The column on the extreme right is
the ones column (just like in our numbering system).  The second column to the
left  of the first is the twos column.   The third column is the fours column,
the fourth is the eights column,  the fifth is the sixteens column,  the sixth
is  the thirty-twos column,  the seventh is the sixty-fours  column,  and  the
eighth is the one-hundred-and-twenty-eights column.   Each column is two times
as  large as the column to its right,  so the example number would equal (1  x
128) + (0 x 64) + (0 x 32) + (1 x 16) + (0 x 8) + (1 x 4) + (1 x 2) + (0 x 1),
or 150.  All this because a computer can't count past one.

     Now  that we know this,  it is possible to quickly figure out some of the
simpler binary numbers.   What is 10 base two?   10 = (1 x 2) + (0 x 1), which
is  2 in our numbering system.   That means that 11 base two = (1 x 2) + (1  x
1),  which is 3, and that 100 base two = (1 x 4) + (0 x 2) + (0 x 1), which is
4.   Not all that complex,  is it?   When the numbers get long, like when they
have  more  than 8 numerals in them,  you might need some scratch paper  or  a
calculator but the method doesn't get any more complex.

     Ready to tackle hexadecimal numbers?   They are a little bit tougher than
binary numbers because the base is 16,  so read carefully.   While the  binary
numbering  system  only  needed two of the digits (0 and 1) from our  base  10
counting numbers,  the hexadecimal numbering system needs 16.   Unfortunately,
there are only 10 from which to choose and that leaves us six short.   This is
where the confusion begins.  The six digits needed to complete the hexadecimal
numbers were borrowed from the alphabet,  beginning with A and ending with  F,
so  if  you  were counting you would start with 0 and count to  F  before  you
reached 10 (in base 16) like this: 0,1,2,3,4,5,6,7,8,9,A, B,C,D,E,F, where A =
10 (base 10),  B = 11 (base 10),  C = 12 (base 10),  D = 13 (base 10),  E = 14
(base 10),  and F = 15 (base 10).  Instead of counting from 0 to 9 in the ones
column, you count from 0 to F.

     OK,  time  to decipher a hexadecimal number,  which will help make  clear
what was just stated.  We will start with 1B.  The column on the extreme right
is  the  ones column (just like in our numbering system).   The column on  the
left  is  16 times the ones column or the sixteens column (remember  that  the
base is the key).   That means that 1B = (1 x 16) + (B x 1) = 16 + B = 16 + 11
(remember that B = 11 in base 10) = 27 (base 10).  Let's take another, 21.  21
= (2 x 16) + (1 x 1) = 32 + 1 = 33 (base 10).  Do you see how it works?

     The  next  logical  question  is why would anyone  want  to  use  such  a
cumbersome   numbering  system?    To find out,   let's look at a  four  digit
hexadecimal number,  EA65.  We already know that the first two columns are the
ones  column and the sixteens column.    Can you guess what the next two  will
be?    Remember  that each column is sixteen times greater than the column  to
its  right  and  you have got it.    Column 3 is  the  two-hundred-fifty-sixes
column and column 4  is the four-thousand-and-ninety-sixes  column.    Knowing
that, EA65 = (E x 4096) + (A x 256) + (6 x 16) + (5 x 1) = (14 x 4096) + (10 x
256)  +  (6  x  16) + (5 x 1) =  57,344 + 2560 + 96 + 5 =  60,005  (base  10).
Quite a large number for  only four  digits,   eh?   That is why someone would
go to such lengths to use  this numbering system,  because all the addressable
memory in an eight bit microprocessor  like the one in our Kaypro machines can
be represented by four digits.   Most  of the references that are expressed in
hexadecimal  numbers  are  either ASCII codes or memory  locations.    It's  a
kind of computer shorthand.

     Although  there are probably people out there that can do it,  I have yet
to meet someone who can translate any arbitrary four digit hexadecimal  number
into base 10 in his head, so don't feel bad if you need a calculator to figure
one of these numbers out.  It is possible, with a little practice, to memorize
some  of the more common ones,  though.   This happens naturally when you  use
something over and over again.  Since most of you will not have an opportunity
to  use  these  numbers over and over again,  don't be overly  impressed  with
someone who can spout them off like a grocery list.  You can do the same thing
in  any  area that you are familiar with,  like classic  literature,  or  auto
mechanics, or travel.

     That is all there is to binary and hexadecimal numbers.   I hope that you
came  away  with  an idea of what they are,   at least,   and maybe  a  better
understanding of how to convert them to our numbering system.

[ Excerpted from our April 1985 newsletter - Ed. ]
