___________________________________________________________________________________________________________________________
DECIMAL
This short tutorial explains how to convert Decimal
between different bases, including binary.
Converting
decimal to binary (or another base):
Converting a
base 10 number to binary (base 2) is very straightforward. You repeatedly
divide the number by 2, each time recording the remainder. At the end of this
line up all of the remainders and reverse their order. For example:
CONVERTING DECIMAL TO BINARY
Converting
20 (dec) to binary - step 1 |
20/2 = 10 (+ remainder 0) |
Once the
answer (without remainder) equals 0, stop. The remainders from each division
were: 0,0,1,0,1, reverse these digits to get the result. 20dec = 10100bin
By replacing 2
with a different number, one can convert to that base. Here's an example
showing 14dec being converted to base 8 (octal):
CONVERTING DECIMAL TO OCTAL
Converting 14dec to octal |
14/8 = 1 (6 remainder) The
remainders were 6,1, reversed this is 16 14dec =
16oct |
So what about
hexadecimal? The process is the same, but with one extra thing to keep in mind:
hexadecimal is base 16, and hence makes use of 6 extra symbols (ABCDEF). A =
10, and F, 15. 16 is written as 10. When converting to any base above 10 you
must keep in mind that a remainder above equal to or greater than 10 has to be
written using the correct symbol.
CONVERTING DECIMAL TO HEXADECIMAL
Converting 1446dec to hexadecimal |
1446/16 = 90 (6 remainder) The
remainders were 6,10,5. 10 should be
written as A. Reversed, this equals 5A6 1446dec =
5A6hex |
CONVERTING BINARY TO DECIMAL
Converting
binary (or another base) to decimal:
A decimal number can be represented as 100s, 10s and units, so 234 is 2
hundreds, 30 tens and 4. Each digit in a number has a place value and a face
value. The face value is a number's actual value, while the place value is a
digit's value in the base to which it belongs, and depends on its position in
the number. These are illustrated in the next example:
Place values: |
Number: 1589 Number:
1 5
8 9 |
Knowing this,
it is possible to convert between bases easily. The next example converts
11011bin to decimal:
Step 1: find the place value
and face value of each digit:
Digit:
1 1 0 1 1
Face value: 1 1 0 1 1
Place value: 16 8 4 2 1
Step 2: Multiply each digit's
face value by its place value and add all together:
(1*16)+(1*8)+(0*4)+(1*2)+(1*1)
16+8+2+1 = 27
11011bin =
27dec
It may seem a
bit unnecessary to bother with face values for binary conversion, however with
higher bases you can see why these are important. The next example shows how to
convert 4C9hex to decimal:
Digit
:
4 C 9
Face value : 4 12 9 (Reminder: C means 12 -
A=10,B=11,C=12,D=13,E=14,F=15)
Place value: 256 16 1
(256*4)+(16*12)+9
1024+192+9 = 1225
4C9h = 1225d
CONVERTING DECIMAL TO
HEXADECIMAL
Steps:
Note: a remainder in
this topic refers to the left over value after performing an integer division.
Example 1
Convert the number 1128
DECIMAL to HEXADECIMAL
NOTES |
DIVISION |
RESULT |
REMAINDER
(in HEXADECIMAL) |
Start by
dividing the number by 16. |
1128 / 16 |
70 |
8 |
Then, divide
the result again by 16 In this case,
70/16=4.375. So the integer division result is 4 (throw out anything
after the decimal point) The remainder is (0.375
multiplied with 16, which is 6. |
70 / 16 |
4 |
6 |
Repeat.
Note here that 4/16=0.25. So the integer division result is 0. The remainder is (0.25-0)
multiplied with 16, which is 4. |
4 / 16 |
0 |
4 |
Stop because
the result is already 0 (0 divided by 16 will always be 0) |
|
|
|
Well, here is
the answer. These numbers come from the REMAINDER column values (read from
bottom to top) |
|
|
468 |
Side note: You can get the
remainder of a division using the Modulus or % operator.
Ie: 1128%16=8.
Example 2
Convert the number 256
DECIMAL to HEXADECIMAL
DIVISION |
RESULT |
REMAINDER
(in HEX) |
256 / 16 |
16 |
0 |
16 / 16 |
1 |
0 |
1 / 16 |
0 |
1 |
|
|
|
ANSWER |
|
100 |
Example 3
Convert the number 921
DECIMAL to HEXADECIMAL
DIVISION |
RESULT |
REMAINDER
(in HEX) |
921 / 16 |
57 |
9 |
57 / 16 |
3 |
9 |
3 / 16 |
0 |
3 |
|
|
|
ANSWER |
|
399 |
Example 4
Convert the number 188
DECIMAL to HEXADECIMAL
DIVISION |
RESULT |
REMAINDER |
188 / 16 |
11 |
C (12
decimal) |
11 / 16 |
0 |
B (11
decimal) |
|
|
|
ANSWER |
|
BC |
Note that here, the answer
would not be 1112, but BC. Remember to write down the remainder in hex,
not decimal.
Example 5
Convert the number 590
DECIMAL to HEXADECIMAL
DIVISION |
RESULT |
REMAINDER |
590 / 16 |
36 |
E (14
decimal) |
36 / 16 |
2 |
4 (4
decimal) |
2 / 16 |
0 |
2 (2
decimal) |
|
|
|
ANSWER |
|
24E |