Contents  1-5  6-11  12-16  17-21  22-27   28-33  34 - 38  39-46  Projects   MFC

   Contact
   C
   C++
   Visual Basic
   Java
   JavaScript
   DHTML
   Style Sheets
   About
   Normalization
   Active X
   TDC Binding
   PHP
   Perl and CGI
   Flash
   XML
   SQL
   Chat
   MCSE
   Linux
   Cabling   
 

   
 
    
    

Hexadecimal has a unique relationship to binary.  Recall that all data types, eventually, are reduced to bytes and bits. 
These bites and bits have only two settings, on and off.  For this reason, all data must be represented in base 2.  Let's
look at some different bases:

A soft answer turns away wrath ” - Proverbs
 
1510 = 15 in base 10.    A one in the tens place and a five in the ones place.         10+5=15
178 = 15 in base 8.       A one in the eights place and a seven in the ones place.    8+7=15.
169 = 15 in base 9.       A one in the nines place and 6 in the ones place.               9+6=15
217 = 15 in base 7.       A two in the sevens place and a one in the ones place.       7+7+1=15.

To convert a standard base 10 number to another base, write out a factor table.  Example for base 7:

Columns: 4 3 2 1
Powers of 7: 73 72 71 70
Decimal Value: 343 49 7 1
Pass in: 200 0 4 0 4

Answer = 4047 

To convert 200 from a decimal value, base 10, to base 7, look at the chart and choose which number to use first.  The fourth column, 343, is too large.  It is greater than 200 so we know it is 0 and we need not worry about it.  In the 49 column, 49 will go into 200 4 times, with 4 left over. Place a 4 under the 49's column.  The 4 left over is for the 7's column.  0 sevens will go into 4, so place a 0 in that column.  4 is still left over, 4 ones will go into 4 four times.  Place a 4 in the ones column.  So 20010 (in base 10) is 4047  (in base 7).

Let's try converting 968 to base 6: 

Columns: 5 4 3 2 1
Powers of 6: 64 63 62 61 60
Decimal Value: 1296 216 36 6 1
Pass in: 968 0 4 2 5 2

Answer = 42526 

There are no 1296's in 968, so column 5 is 0.  There are 4 216's in 968, so column 4 is 4, with a remainder of 104 left over.  There are 2 36's in 104, so column 3 is 2 with 32 left over.  There are 5 6's in 32, so column 2 is 5, with 2 left over.  There are 2 1's in 2, so column 1 is 2, with nothing left over.  So 96810 (in base 10) is 42526  (in base 6).

To convert back from base 6 to base 10, we would multiply.  Example for 42526:

4 * 216 =  864
2 * 36 =    72
5 * 6 =     30
2 * 1 =      2     
              968
Total = 968

Binary - Binary (base 2) is the ultimate base for computers, for 0 can be false and 1 true, 0 can be off and 1 on.  You can represent the fundamental truth of every circuit - there is power or there isn't.

To convert 88 to base 2:

Columns: 8 7 6 5 4 3 2 1
Powers of 2: 27 26 25 24 23 22 21 20
Decimal Value: 128 64 32 16 8 4 2 1
Pass in: 88 0 1 0 1 1 0 0 0

Answer = 10110002

There are no 88's in 128, so column 8 is 0.  There is 1 64 in 88, so column 7 is 1, with 24 left over.  There are 0 32's in 24, so column 6 is 0, with 24 left over.  There is 1 16 in 24, so column 5 is 1, with 8 left over.  There is one 8 in 8, so column 4 is 1, with nothing left over.  The last 3 columns are 0 because nothing is left over.

To test the answer convert it back by multiplying:

1 * 64 =  64
0 * 32 =  0
1 * 16 =  16
1 * 8 =    8
0 * 4 =    0
0 * 2 =    0
0 * 1 =    0      
             88
Total = 88

Now let's look at some physical memory sizes:

byte = 8 bits
nybble = 4 bits
kilobyte = 1024 bytes
megabyte = 1024 kilobytes
gigabyte = 1024 megabytes

Notice that all of the above can be reduced to base 2.  With 8 binary digits you can represent 256 values, 255 if all 8 bits are set to 1 and 0 if all 8 bits are set to 0.  In ASCII, every letter, punctuation, numeral and character is given a binary representation.  The lowercase letter "a" is represented as "01100001" in binary. This translates to the number "97" in decimal (base 10).  That is why the ASCII code for "a" is "97". 

Hexadecimal - Base 16 is called hexadecimal.  Translating from base 2(binary), to base 16(hexadecimal) is much more efficient than translating from base 2 to base 10.  This is why it is so useful in programming.  In base 16, there are 16 numerals:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F 

After 0-9, hexadecimal continues up the scale with A=10, B=11, C=12, D=13, E=14, F=15.

To convert 3980 to hexadecimal: 

Columns: 9 8 7 6 5 4 3 2 1
Powers of 16: 168 167 166 165 164 163 162 161 160
Decimal Value: 4,294,967,296 268,435,456 16,777,216 1,048,576 65,536 4,096 256 16 1
Pass in: 3980 0 0 0 0 0 0 15 8 12

Answer = F8C16


Remember:   A=10, B=11, C=12, D=13, E=14, F=15,
                    so 15 and 8 and 12 = F and 8 and C
                   

There are 0 4096's in 3980, so column 4 is 0.  There are 15(or F) 256's in 3980, so column 3 is F, with 140 left over.  There are 8 16's in 140, so column 2 is 8, with 12 left over.  There are 12(or C) ones in 12, so column 1 is C with nothing left over.

To translate F8C from hexadecimal to decimal, multiply:

F * 256 = 3840
8 * 16 =   128
C * 1 =     12    
              3980
15 * 256 = 3840
8 * 16 =    128
12 * 1 =    12      
                3980

To translate FC to binary, first translate it to base 10, and then to binary:

Columns: 2 1
Powers of 16: 161 160
Hex value: F C
Translates to: 15 12
Value: 15 x 16 12 x 1
Now add the results:

F(15) * 16 =  240
C(12) * 1 =   12    
Total =        25210 


Now that we know that FC in hexadecimal (base 16) is 252 in base 10, let's translate it to binary (base 2):

Columns: 9 8 7 6 5 4 3 2 1
Powers of 2: 28 27 26 25 24 23 22 21 20
Decimal Value: 256 128 64 32 16 8 4 2 1
Pass in: 252 0 1 1 1 1 1 1 0 0

Answer = 111111002

There are no 256's in 252, so column 9 is 0.  There is 1 128 in 252, so column 8 is 1, with 124 left over.  There is 1 64 in 124, so column 7 is 1, with 60 left over.  There is 1 32 in 60, so column 6 is 1, with 28 left over.  There is 1 16 in 28, so column 5 is 1, with 12 left over.  There is 1 8 in 12, so column 4 is 1, with 4 left over.  There is one 4 in 4, so column 3 is 1, with nothing left over.  The remaining columns are 0 because nothing is left.

Shortcut:  If you split this 8-digit binary number into 2 sets of 4 digits each, you can use a shortcut to convert them to hexadecimal:

1111            1100

The left set, 1111, is 15 in decimal:

  1  *  1  =  1
  1  *  2  =  2 
  1  *  4  =  4
  1  *  8  =  8    
 Total =    15           15 =  F in hexadecimal.
The right set, 1100, is 12 in decimal:

  0  *  1  =   0
  0  *  2  =   0
  1  *  4  =   4
  1  *  8  =   8   
Total =      12            12 =  C in hexadecimal.

Therefore,  FC is the hexadecimal value of 1111 1100.

This shortcut always works.  Take any binary number, split it into sets of 4 digits, translate each set of 4 into hexadecimal, and put the hexadecimal results together to get the entire number in hexadecimal.  This shortcut could definitely save us some time.


©2004 C. Germany