As we have learned conversion from other systems to the decimal system in our article “Understanding the ‘inside out’ of number system: (Part 1 )”. Now we are going to understand the “ conversion between:

1. Binary and octal: In this conversion, we are going to focus on how can we convert binary to octal numbers and how to convert octal to binary digits.
2. Binary and hexadecimal: In this conversion, we will understand in detail how to convert binary to hexadecimal and how to convert hexadecimal to binary digits.

## Conversion between binary and octal:

Each digit of an octal number is equivalent to three binary digits because any octal number ( 0 to 7) can be represented by three binary digits as shown in the given table.

## Conversion from Binary to Octal number system:

The binary digits are split into two groups of three digits starting from right to left. Zeros can be added at the left end to make a complete group of three digits if required. Each group represents an equivalent octal digit.

Octal number system provides an appropriate way of converting large binary numbers into more dense and smaller groups.

There are multiple ways to convert a binary number into an octal number. You can transform using direct methods or indirect methods. First, you need to convert a binary into other base systems.

Since there are only 8 digits (from 0 to 7) in the octal number system, so we can represent any digit of octal number system using only 3 bit as following below.

Octal SymbolBinary equivalent
0000
1001
2010
3011
4100
5101
6110
7111

So, if you make each group of 3-bit binary input number, then replace each group of binary number from its equivalent octal digits. That will be the octal number of a given number. Note that you can add any number of 0’s in leftmost bit (or in most significant bit) for integer part and add any number of 0’s in rightmost bit (or in the least significant bit) for fraction part for completing the group of 3 bit, this does not change the value of input binary number.

Here we have the binary numbers which we are going to convert to octal numbers: (10111010001111)

Binary:    010  111  010  001  111

Octal:      2 7   2 1 7

So, we got the octal numbers (27217).

## Conversion from Octal to Binary number system:

An octal number can be easily converted to a binary number by replacing each octal digit with the corresponding three binary digits.

There are various direct or indirect methods to convert an octal number into a binary number. In an indirect method, you need to convert an octal number into other number systems (e.g., decimal or hexadecimal), then you can convert into binary number by converting each digit into binary numbers from the hexadecimal system and using conversion system from decimal to binary number.

Here we have an octal number which we are going to convert in binary digits: ( 42153 )8

Octal: 4   2   1   5 3

Binary: 100 010 101  011

So, we got the answer ( 100010001101011 )2

## Conversion between Binary and Hexadecimal:

Like the octal system, the hexadecimal system can be easily derived from the binary system. Each Hexadecimal digits (0-9 and A- F) is equivalent to four binary digits as shown in the table given under:

Decimal Hex Binary
0 0 0
1 1 1
2 2 10
3 3 11
4 4 100
5 5 101
6 6 110
7 7 111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
16 10 10000
17 11 10001
18 12 10010
19 13 10011
20 14 10100
25 19 11001
26 1A 11010
27 1B 11011
28 1C 11100
29 1D 11101
30 1E 11110
31 1F 11111
32 20 100000
33 21 100001
34 22 100010

Conversion between binary and hexadecimal is simply accomplished by grouping the binary numbers into four digits replacing each group with a hexadecimal equivalent digit.

Hexadecimal number system provides an appropriate way of converting large binary numbers into more compact and smaller groups. There are various ways to convert a binary number into a hexadecimal number. You can convert using direct methods or indirect methods. First, you need to convert a binary into other base systems (e.g., into a decimal, or into octal). Then you need to convert it into a hexadecimal number.

Since there are only 16 digits (from 0 to 7 and A to F) in the hexadecimal number system, so we can represent any digit of hexadecimal number system using only 4 bit as following below.

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

Here we have the binary numbers to convert in hexadecimal number system (111010000110111000)2

In this conversion we make the pair of four digits, so we have to add two leading zeros to make perfect pairs like:

Binary numbers :  0011  1010  0001  1011  1000

Hexadecimal:        3 A 1 B 8

We got the answer (3A1B8)16. So, if you make each group of 4-bit binary input number, then replace each group of binary number from its equivalent hexadecimal digits. That will be a hexadecimal number of given numbers. Note that you can add any number of 0’s in leftmost bit (or in most significant bit) for integer part and add any number of 0’s in rightmost bit (or in the least significant bit) for fraction part for completing the group of 4 bit, this does not change the value of input binary number.

## Conversion from Hexadecimal to Binary number system:

Conversely, a hexadecimal number can be converted into binary by replacing each digit by the equivalent four binary digits.

Here we have the hexadecimal number system to change in binary digits: (5DC7).

Hexadecimal number: 5 D C 7

Binary Numbers: 0101 1101 1100 0111

So, we got the answer 0101110111000111

This method of using the binary equivalent of digits of numbers in Interbase conversion is called “Direct Method”.