Free OpenGL Example
Click here to go to the OpenGL template
http://au.ebid.net/perl/normal.cgi?ref=855501&mo=register-main

Assembly theory explained


Binary and Hexadecimal notation


In any tutorial on assembly theory we must tackle the subject of HEXADECIMAL notation. While knowing bits and bytes is very necessary, useful and a bit of fun; knowing HEXADECIMAL notation is not.

Firstly, the word 'notation' simply means 'numbering system' or 'base'.

We use decimal notation every day and don't think too much about it. Had we been taught a different numbering system, in school, etc, then the decimal system would look as strange to us as the HEXADECIMAL system looks to a novice. As those who lived at the time when the decimal/metric system was introduced found out.

In the decimal system we are taught that when we count up to ten we then set the units to 0 and increment the tens. Therefore it is referred to as base ten notation.
For example:
                | hundreds | tens | units |
                +----------+------+-------+
                |    0     |  0   |   0   |   ...written as  0
                |    0     |  0   |   1   |                  1
                |    0     |  0   |   2   |                  2
                |    .     |  .   |   .   |                  .
                |    .     |  .   |   .   |                  .
                |    .     |  .   |   .   |                  .
                |    0     |  0   |   9   |                  9
                |    0     |  1   |   0   |                 10
The more correct way to write the values of the columns is to use the base value raised to an increasing power.
For example:

                |   10^2   | 10^1 | 10^0  |
                +----------+------+-------+
                |    0     |  0   |   0   |   ...written as  0
                |    0     |  0   |   1   |                  1
                |    0     |  0   |   2   |                  2
                |    .     |  .   |   .   |                  .
                |    .     |  .   |   .   |                  .
                |    .     |  .   |   .   |                  .
                |    0     |  0   |   9   |                  9

In the BINARY number system (base 2) we carry over to the next column after we have reached the base number 2, so it looks like...
     |  2^3   |  2^2  | 2^1  |  2^0  |
     +--------+-------+------+-------+
     |   0    |   0   |  0   |   0   | ...written as  0000
     |   0    |   0   |  0   |   1   |                0001
     |   0    |   0   |  1   |   0   |                0010
     |   .    |   .   |  .   |   .   |                  .
     |   .    |   .   |  .   |   .   |                  .
     |   .    |   .   |  .   |   .   |                  .
     |   1    |   1   |  1   |   0   |                1110
     |   1    |   1   |  1   |   1   |                1111
In HEXADECIMAL notation we do not increment the next column until we count up to 16. Therefore HEXADECIMAL is a base 16 numbering system. The problem is that, as we count up and reach ten we feel inclined to write 10, but this would make writing the numbers look messy, so they decided to use the first letters of the alphabet to write the numbers from 10 to 15.
For example:
        A = 10
        B = 11
        C = 12
        D = 13
        E = 14
        F = 15
       10 = 16
So the HEXADECIMAL numbering system looks like:
      |   16^2   | 16^1 | 16^0  |
      +----------+------+-------+
      |    0     |  0   |   0   | ...written as  0 ...and in decimal = 0
      |    0     |  0   |   1   |                1                     1
      |    0     |  0   |   2   |                2                     2
      |    .     |  .   |   .   |                .                     .
      |    .     |  .   |   .   |                .                     .
      |    .     |  .   |   .   |                .                     .
      |    0     |  0   |   9   |                9                     9
      |    0     |  0   |   A   |                A                    10 
      |    0     |  0   |   B   |                B                    11
      |    0     |  0   |   C   |                C                    12 
      |    0     |  0   |   D   |                D                    13
      |    0     |  0   |   E   |                E                    14
      |    0     |  0   |   F   |                F                    15
      |    0     |  1   |   0   |               10                    16
      |    0     |  1   |   1   |               11                    17
So what is it used for? It was used more in the early days of computing because it is easier to convert from a HEXADECIMAL byte value to a BINARY byte value and visa versa. Programmers would commit to memory the following conversions and could quickly calculated which bits in a byte where on or off.
      | hexadecimal | binary |
      +-------------+--------+
      |      0      |  0000  |
      |      1      |  0001  |
      |      2      |  0010  |
      |      .      |    .   |
      |      .      |    .   |
      |      E      |  1110  | 
      |      F      |  1111  |
For example:
A HEXADECIMAL number is always one or two characters, such as AE, and programmers knew to replace each HEXADECIMAL character with its binary equivalent. A & E in HEXADECIMAL equals 1010 & 1110 in BINARY. So programmers knew that ...
    AE = 10101110
   or
    F0 = 11110000
   or
     B = 00001011    ....(Implied 0 before the B)
and so on.
It's not quite as necessary these days because programmers are now less worried about wasting memory and will use a whole byte to hold data rather than a bit within a byte.


Copyright © 1998 - 2010 Alan Baylis, All Rights Reserved