p.s. I Love You

I may be funny to my friends but my family just thinks I'm strange.

Name:
Location: French Guiana

Monday, August 15, 2005

What the hex she talking about?

I ran across someone trying to sum hex numbers in excel. Not being an expert in excel she couldn't figure it out. Now, I have an expert rating in excel but I'd never heard of hex numbers. Shoot, the only numbers I know are 1, 2, 3, 4... (if you want to know the answer, you'll have to ask me.)

The Hexadecimal Number Base System
A big problem with the binary system is verbosity. To represent the value 202 requires eight binary digits. The decimal version requires only three decimal digits and, thus, represents numbers much more compactly than does the binary numbering system. This fact was not lost on the engineers who designed binary computer systems.

When dealing with large values, binary numbers quickly become too unwieldy. The hexadecimal (base 16) numbering system solves these problems. Hexadecimal numbers offer the two features:

hex numbers are very compact
it is easy to convert from hex to binary and binary to hex.

Since we'll often need to enter hexadecimal numbers into the computer system, we'll need a different mechanism for representing hexadecimal numbers since you cannot enter a subscript to denote the radix of the associated value.

The Hexadecimal system is based on the binary system using a Nibble or 4-bit boundary. In Assembly Language programming, most assemblers require the first digit of a hexadecimal number to be 0, and we place an H at the end of the number to denote the number base.

The Hexadecimal Number System:

uses base 16
includes only the digits 0 through 9 and the letters A, B, C, D, E, and F

In the Hexadecimal number system, the hex values greater than 9 carry the following decimal value:

Binary Octal Decimal Hex
0000B 00Q 00 00H
0001B 01Q 01 01H
0010B 02Q 02 02H
0011B 03Q 03 03H
0100B 04Q 04 04H
0101B 05Q 05 05H
0110B 06Q 06 06H
0111B 07Q 07 07H
1000B 10Q 08 08H
1001B 11Q 09 09H
1010B 12Q 10 0AH
1011B 13Q 11 0BH
1100B 14Q 12 0CH
1101B 15Q 13 0DH
1110B 16Q 14 0EH
1111B 17Q 15 0FH
1 0000B 20Q 16 10H

This table provides all the information you'll ever need to convert from one number base into any other number base for the decimal values from 0 to 16.

To convert a hexadecimal number into a binary number, simply brake the binary number into 4-bit groups beginning with the LSB and substitute the corresponding four bits in binary for each hexadecimal digit in the number.

For example, to convert 0ABCDh into a binary value, simply convert each hexadecimal digit according to the table above. The binary equivalent is:

0ABCDH = 0000 1010 1011 1100 1101

To convert a binary number into hexadecimal format is almost as easy. The first step is to pad the binary number with leading zeros to make sure that the the binary number contains multiples of four bits. For example, given the binary number 10 1100 1010, the first step would be to add two bits in the MSB position so that it contains 12 bits. The revised binary value is 0010 1100 1010.

The next step is to separate the binary value into groups of four bits, e.g., 0010 1100 1010. Finally, look up these binary values in the table above and substitute the appropriate hexadecimal digits, e.g., 2CA.

The weighted values for each position is as follows:

16^3 16^2 16^1 16^0
4096 256 16 1


--------------------------------------------------------------------------------

1 Comments:

Blogger Elisa said...

Hmm...this sounds vaguely familiar.... ;) Thanks for stopping by, I was glad to come across your blog thanks to the link you posted in mine. You have a nice sense of humor. Can't wait to hear about more of the two Princess' adventures.

P.S. Can you believe that we software engineers are made to memorize the table you just posted? Still, that doesn't seem to help much when you need to add a long stream of them hex numbers together. It is more useful, as it turns out, for writing clever messages in obscure chip memory locations. Texas Instruments, for instance, likes to initialize the memory of its DSP chips with the hex value 0xC0FFEE! ;)

August 15, 2005 at 11:37 PM  

Post a Comment

<< Home