Each octal digit can be replaced by its 3-bit equivalent binary number and each Hexadecimal digit can be replaced by its 4-bit binary number to form the binary equivalent. This process is illustrated in Figures 2.1 and 2.2 Below.

Fig. m010222.1 Conversion process from Hexadecimal to Binary

Fig. m010222.2 Conversion process from Octal to Binary

Conversion from Binary to Octal and Hexadecimal:

Reverse the process above; start from the least significant bit and replace each 3-bits by their Octal equivalent or each 4-bits by their Hexadecimal equivalent. If there are less than 3-bits (for Octal conversion) or less than 4-bits (for the Hexadecimal conversion), fill the most significant bits with 0s. Figures 2.3 and 2.4 illustrate this process.

Fig. m010222.3 Conversion process from Binary to Hexadecimal

Fig. m010222.4 Conversion process from Binary to Octal

Conversion between Octal and Hexadecimal:

The easiest way to convert between Octal and Hexadecimal is to first convert to Binary and then reconvert to the other system.

Example on converting from Hexadecimal to Octal

Converting (FA07)_{16} to Octal:

First convert the hexadecimal number FA07h to binary:

1

1

1

1

1

0

1

0

0

0

0

0

0

1

1

1

Now convert this back to Octal:

1

7

5

0

0

7

Conversion From Decimal to Binary, Octal or Hexadecimal

To convert from decimal to any numbering system with base r :

The decimal number is divided by r,

Keeping the remainder aside, the result is further divided by r, and the new remainder is kept aside,

The new result is divided again by r, and so on till the result is less than r and this would be the last remainder,

The remainders make up the equivalent base-r number, with the last remainder being the most-significant digit and the first remainder being the least-significant digit.

Examples:

The examples below best illustrate the conversion process from decimal to binary, octal and hexadecimal.

Converting 122d to binary, octal and hexadecimal

First conversion to Binary:

Dividend

Quotient

Remainder

122

61

0 <--- LSB

61

30

1

30

15

0

15

7

1

7

3

1

3

1

1

1

0

1 <--- MSB

Hence the result is:

1

1

1

1

0

1

0

Second, the conversion to Octal:

Dividend

Quotient

Remainder

122

15

2 <--- LSD

15

1

7

1

0

1 <--- MSD

Hence the result is:

1

7

2

Notice that it took us only 3 steps to finish compared to 7 steps for the binary conversion.

Finally, the conversion to Hexadecimal:

Dividend

Quotient

Remainder

122

7

10 (i.e. A)

7

0

7

Hence the result is:

7

A

Notice that it took us only 2 steps to finish the conversion!.

An Important note

It takes less steps to convert from decimal to hexadecimal,

So a quick way to convert from decimal to binary is to convert first to hexadecimal and then from hexadecimal to binary,

In the example above the 7A result would have been very easily converted to its binary equivalent: 1111010.

Yet another method for converting decimal numbers to binary

As one become more experienced with the powers of two, the decimal-to-binary conversion process could become direct and fast.

First familiarize yourself with the powers of two listed in the table below:

Powers of 2

Power

Decimal Equivalent

In English!

2^{0}

1

one

2^{1}

2

two

2^{2}

4

four

2^{3}

8

…

2^{4}

16

…

2^{5}

32

…

2^{6}

64

…

2^{7}

128

…

2^{8}

256

1/4 kilo

2^{9}

512

half-kilo

2^{10}

1,024

Kilo

2^{11}

2,048

two Kilos

2^{12}

4,069

4 Kilos

2^{13}

8,192

8 Kilos

2^{14}

16,384

16 Kilos

2^{15}

32,768

32 Kilos

…

…

…

2^{20}

1,048,576

Mega

2^{21}

2,097,152

2 Mega

…

…

…

2^{30}

1,073,741,824

Giga

2^{31}

2,147,483,648

2 Giga

…

…

…

2^{40}

1,024 Giga

Tera

…

…

…

Now to convert a decimal number to binary, the procedure is very simple:

Procedure for converting from Decimal to Binary

Determine the highest possible power of two that is less or equal to the number. For example, the highest power of two in 122d is 64 and the highest power of two in 526d is 512 and so on.

Put a 1 in the bit position corresponding to the highest power of two found above. So for a highest power of two of 64, we put 1 in the seventh bit position, and for a highest power of two of 512, we put a 1 in the 10th bit position. This is now our most significant bit.

Subtract the highest power of two found in step 2 above from the number.

Examine the remaining number:

If it is larger or equal than the next power of two, then put a 1 in the next bit position and subtract this power of two from the number

If it is less than the next power of two, put a 0 in the next bit position and repeat step 3 till all bit positions are filled.

The above process is best illustrated using an example:

Example: Converting 76d to Binary

The highest power of 2 less or equal to 76 is 64, hence the seventh (MSB) bit is 1:

1

.

.

.

.

.

.

Subtracting 64 from 76 we get 12.

12 is less than the next power of 2 which is 32, hence the sixth bit position is 0:

1

0

.

.

.

.

.

12 is still less than the next power of 2 which is 16, hence the fifth bit position is 0:

1

0

0

.

.

.

.

12 is greater than the next power of 2 which is 8, hence the fourth bit position is 1:

1

0

0

1

.

.

.

We subtract 8 from 12 and get 4, which will be compared to the next power of 2.

4 is equal to the next power of 2 which is 4, hence the third bit position is 1:

1

0

0

1

1

.

.

Subtracting 4 from 4 yield a zero, hence all the left bits are set to 0 to yield the final answer: