Binary numbers
Computers use the binary system, which consists of ones and zeroes. Depending on their position they are of different value. See chart.
|
Position |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
Value |
2*107 |
2*106 |
2*105 |
2*104 |
2*103 |
2*102 |
2*101 |
2*100 |
Decimal to Binary
The process of converting a decimal number into a binary number is very simple. It is best shown with an example:
Example 1
Decimal number to convert: 21110
First you must convert 211 into powers of 2:
211 = 128 + 64 + 16 + 2 + 1
All you have to do now is to write a one in the positions for 128, 64, 16, 2 and 1. You add zeroes to the other positions:
21110 = 110100112
Binary to Decimal
Converting binary numbers into decimal numbers is done in the same way, only reversed.
Hexadecimal numbers
Instead of using only the numbers 0-9 as in the decimal system, the hexadecimal system uses the numbers 0-9 and the letters A-F. See chart.
|
Decimal |
Hexadecimal |
|
0 |
0 |
|
1 |
1 |
|
2 |
2 |
|
3 |
3 |
|
4 |
4 |
|
5 |
5 |
|
6 |
6 |
|
7 |
7 |
|
8 |
8 |
|
9 |
9 |
|
10 |
A |
|
11 |
B |
|
12 |
C |
|
13 |
D |
|
14 |
E |
|
15 |
F |
Decimal to Hexadecimal
The process of converting a decimal number into a hexadecimal number is very simple. It is best shown with an example:
Example 1
Decimal number to convert: 21110
The first step is to divide 211 with 16(the base of the hexadecimal system).
211 / 16 = Quota = 13 Remainder = 3/16 -> d0 = 3
13 / 16 = Quota = 0 Remainder = 13 /16 -> d1 = D
This gives us that 21110 = D316.
Hexadecimal to Decimal
The process of converting a hex. number back to a decimal number is even simpler:
Example 2
Hexadecimal number to convert: D316
The number in the first position has a value of: 160.
The number in the second position has a value of: 161.
The number in the third position has a value of: 162.
…….
…….
This gives us that D316 = (D16 * 161) + (316 * 160) = 1310 * 16 + 310 * 1 = 21110.
Binary to Hexadecimal
When you convert binary numbers into hexadecimal numbers, you group the binary number into groups of 4. For example the binary number 0100110110101110 will be grouped as 0100 1101 1010 1110. Then you convert each group into a hexadecimal number. See chart.
|
Decimal |
Binary |
Hexadecimal |
|
0 |
0000 |
0 |
|
1 |
0001 |
1 |
|
2 |
0010 |
2 |
|
3 |
0011 |
3 |
|
4 |
0100 |
4 |
|
5 |
0101 |
5 |
|
6 |
0110 |
6 |
|
7 |
0111 |
7 |
|
8 |
1000 |
8 |
|
9 |
1001 |
9 |
|
10 |
1010 |
A |
|
11 |
1011 |
B |
|
12 |
1100 |
C |
|
13 |
1101 |
D |
|
14 |
1110 |
E |
|
15 |
1111 |
F |
The example from above will be: 01002 = 416
11012 = D16
10102 = A16
11102 = E16
So 01001101101011102 = 4DAE16
Hexadecimal to Binary
To convert a hexadecimal number into a binary you simply take each hex. "number" and convert it into a binary code according to the chart.
Jan Johansson
Gothenburg
Sweden
d96jan@ios.chalmers.se