CONVERTING HEXADECIMAL TO BINARY
AND VICE VERSE
THE EASY WAY

 
Converting hex number to binary number is very easy, it's almost trivial.  The only requirement is that you know the equivalent binary value of each hexadecimal "digit" (0 to F); or if not, you must know how to convert them by hand.  Below is a table that show each hexadecimal digit with it's corresponding binary number.  

Note that every binary number on this table consists of four digits.  This is necessary because the maximum hexadecimal digit value is F or 15, which translates to four-digits-binary 1111.

HEX BINARY
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111

(Technically, any trailing 0 at the beginning of a number doesn't mean anything.  So, binary 0010 is the same as binary 10, but for conversion purpose, include the trailing 0s.)

To convert a hexadecimal number to binary.  Just write down the binary value of each hex digit. 

Example 1:
To convert hexadecimal F8 to binary, write down the binary for F first, then the binary for 8.  
F    8
1111    1000

So, the answer is 11111000.  
This seems too easy, and it is.  Use a calculator to convince yourself.

Another example:
Convert hex number 1A to binary.  

1    A
0001    1010

So, the answer is 00011010.  (Note: Once you got the answer, you can ignore the zeros at the beginning, so this can be also written as 11010.)

More examples: 

hex D   C   C    
bin 1101   1100   1100    
                
hex 1   0   0   3
bin 0001   0000   0000   0011
                
hex F   3   A   2
bin 1111   0011   1010   0010
                

Binary to Hex Example:
This time, let's assume we have a binary number that needs to be converted to hex.  For example, the binary number 11010.  In this case because the number of digits is not a multiple of 4, insert 0s at the beginning to make the number multiple of four.  So it becomes 00011010.  We then separate each four-digits pair and get their corresponding hex values.

0001   1010
1   A   

So, the answer is 1A. 

Memorizing the Table?
I don't recommend memorizing the binary number of each hex digit.  Also, if you don't know where those 0s and 1s comes from, it's easy to make mistakes and not knowing it, or even forget.  I recommend that you know where they come from, and you won't have to worry much about forgetting.  For example, know that 4 is 2^2, so the binary of 4 must be 0100.  Why?  Let's convert it systematically:

DIVISION RESULT REMAINDER
4/2 2 0
2/2 1 0
1/2 0 1

The answer is the remainders being read backward, which is 100.

4 = (0)*2^3 + (1)*2^2  + (0)*2^1 + (0)*2^0

Realize that this is the only way the number 4 in binary can be represented.

ANumber = (b1)*(2^3) + (b2)*(2^2) + (b3)*(2^1) + (b4)*(2^0)

or

ANumber = (b1)*8 + (b2)*4 + (b3)*2 + (b4)*1

where b1, b2, b3, b4 must be either 1 or 0.  

So, let's say we're looking for the binary of 9.  What sequence of bs will sum to 9?  There's always one unique answer:

9 = (1)*8 + (0)*4 + (0)*2 + (1)*1

b1=1
b2=0
b3=0
b4=1

So the binary of 9 is 1001.

How about the binary of 7.  What sequence of bs will sum to 7?  Again, there's only one answer:

7 = (0)*8 + (1)*4 + (1)*2 + (1)*1

b1=0
b2=1
b3=1
b4=1

So the binary of 7 is 0111.

I've added a decimal column to the table; it's shown below.  See Converting Binary.

HEX DECIMAL BINARY
0 0 = 0+0+0+0 0000
1 1 = 0+0+0+1 0001
2 2 = 0+0+2+0 0010
3 3 = 0+0+2+1 0011
4 4 = 0+2+0+0  0100
5 5 = 0+4+0+1 0101
6 6 = 0+4+2+0 0110
7 7 = 0+4+2+1 0111
8 8 = 8+0+0+0 1000
9 9 = 8+0+0+1 1001
A 10 = 8+0+2+0 1010
B 11 = 8+0+2+1 1011
C 12 = 8+4+0+0 1100
D 13 = 8+4+0+1 1101
E 14 = 8+4+2+0 1110
F 15 = 8+4+2+1  1111

 

 

(C) F. Permadi

<<BACK>>

 

permadi@permadi.com
10/2001