deadlock Message Board
[ July Full List | Reply ]

Re: Hex conversion formula
From Thomas Dowers at on 7 Jan '01
replying to Re: Hex conversion formula posted by Jim

>>I'm looking for the conversion formula for hex to decimal.
>Use Windows Calculator...
>From your Start menu, do Run... and enter the word calc.
>Put it in "scientific" view, switch to the Hex option, type
>in your Hex number, then switch to Dec mode and it'll show you
>the conversion.

I found this at Cisco's website:

The URL to this info is

Hexadecimal Numbering Versus Decimal Numbering
Hexadecimal (Hex) numbering uses 0-F (A=10, B=11, C=12, D=13, E=14, and F=15). It is a base-16 numbering system. F is the largest digit that can be used in any position. This is the same as having 9 be the largest number that can be used in any position in a decimal number.

Each digit in a hex number is multiplied by 16 to the power of the digit's position in the hex number, with the first position being the power of (0). Any number to the power of 0 is 1. Therefore, (1*(100))=1=(1*(160)).

Consider the hex number AA. It can be written in the more explicit form of A*(161) + A*(160), which is one way to convert a hex number into a decimal number. In this case, A*(161) equals decimal 160, and A*(160) equals decimal 10, resulting in the formula 160+10=170. AA in hex equals 170 in decimal. Notice that it takes eight binary digits---10101010---to write the binary equivalent of 170 (decimal), but it takes only two hex numbers. This is one reason why hex is such a popular numbering system.

The primary use of hex numbering in addressing schemes is to provide a shorthand method of writing binary octets. You seldom have to deal with hex numbers greater than two digits. Layer two Media Access Control (MAC) addresses are typically written in hex. For Ethernet and Token Ring, these addresses are 48 bits, or six octets. Because these addresses consist of six distinct octets, they can be expressed as six hex numbers instead.

Instead of writing 10101010.11110000.11000001.11100010.01110111.01010001, you can write the much shorter hex equivalent: AA.F0.C1.E2.77.51. To make handling hex versions of MAC addresses even easier, the dots are placed only after each four digits, as in AAF0.C1E2.7751.

Here is an easy way to manipulate hex numbers that can help when you need to convert hex to binary in a hurry and don't have a calculator handy. Break the two-digit hex number into two distinct sections: AA becomes A.A. Write the binary equivalent of each number: 1010.1010 (1010=10=A). Then put them back together again: 10101010=AA. Try another one: FA=F.A=1111 to 1010=11111010.

Although it is unusual to work with hex numbers larger than two digits, the concept of manipulating a four-digit hex number is presented here in order to provide an advanced discussion on hex numbering.

Consider the hex number FADE. You can write it using the same system as before: F*(163) + A*(162) + D*(161) + E*(160)= 64222 in decimal. How do you arrive at this answer? Look at the following method for writing out the same number:

F*(163) = 61440

+ A*(162) = 2560

+ D*(161) = 208

+ E*(160) = 14

= 64222

Some people prefer to think about hex numbers in terms of the values represented by each position. The positions in this example are 3 2 1 0. These are the powers the base is raised to for each position. For hex, the resulting values in decimal are as follows: 4096 256 16 1. Once again, 163=4096, 162=256, 161=16, and 160=1.

Compare this to the decimal values for the same four positions by using base-10: 1,000 100 10 1. Once again, 103=1,000; 102=100; 101=10; and 100=1. Just as the decimal numbering system has a ten thousands place, a one thousands place, and a thousands place, the hex numbering system has a 4096 place, a 256 place, a 16 place, and so on.

The system for changing hex numbers into binary numbers is the same as changing decimal numbers into binary numbers. It uses iterative division by 2 until a remainder of 1 is achieved. Let's convert AA in hex to its binary equivalent. You start by dividing the number to be converted (AA) by two. The result is divided by two again, and the remainder is written off to the side. Remainders are written from right to left.

AA/2 = 55 R 0 Binary result so far 0.

55/2 = 2A R 1 Binary result so far 10.

2A/2 = 15 R 0 Binary result so far 010.

15/2 = A R 1 Binary result so far 1010.

A/2 = 5 R 0 Binary result so far 01010.

5/2 = 2 R 1 Binary result so far 101010.

2/2 = 1 R 0 Binary result so far 0101010.

1/2 = 0 R 1 Binary result so far 10101010.

You can do this again using the decimal equivalents of the hex numbers to make it easier to see what is going on:

170/2 = 85 R 0 Binary result so far 0.

85/2 = 42 R 1 Binary result so far 10.

42/2 = 21 R 0 Binary result so far 010.

21/2 = 10 R 1 Binary result so far 1010.

10/2 = 5 R 0 Binary result so far 01010.

5/2 = 2 R 1 Binary result so far 101010.

2/2 = 1 R 0 Binary result so far 0101010.

1/2 = 0 R 1 Binary result so far 10101010.

Reply to this message

Required Details
Your name:

Optional Details
Home page title:
Home page URL:
(if you'd like to receive automatic replies by email)

Your Message