In this tutorial, you will learn the fundamentals of number system conversions, including how to convert between decimal, binary, octal, and hexadecimal systems. You will explore the processes for converting decimal to other bases and vice versa, as well as binary to octal and hexadecimal conversions. Additionally, you will understand the importance of these conversions in computer applications.
Contents:
- Decimal to Binary, Octal, and Hexadecimal Conversion
- Binary, Octal, and Hexadecimal to Decimal Conversion
- Decimal to Binary Conversion
- Binary to Octal Conversion
- Octal to Binary Conversion
- Binary to Hexadecimal Conversion
- Hexadecimal to Binary Conversion
- Hexadecimal to Decimal Conversion
- Decimal to Hexadecimal Conversion
- Octal to Hexadecimal Conversion
- Hexadecimal to Octal Conversion
- Decimal to Octal Conversion
- Octal to Decimal Conversion
- Importance of Number System Conversions
Decimal to Binary, Octal, and Hexadecimal Conversion
The process for conversion from Decimal to any other base follows these basic steps.
- For a given number in decimal, we divide the integer part of the number by radix value, which we have to convert into and go on dividing till we get zero as quotient.
- We keep a track of all the remainders at all stages and then write them in the reverse order that is from bottom-up, which gives us the integer part of the number in the required base.
- Due to writing in reverse order, the first remainder becomes the least significant bit (LSB) and the last remainder becomes the most significant bit (MSB).
- To obtain the fractional part, we multiply the entire fractional part with the radix and write down the integer part obtained from it.
- We can repeat this multiplication step with the newly obtained fractional part from the previous multiplication, till we get the fractional part as zero and get the perfect fractional equivalent.
- We write down the digits in the order we performed the multiplications. Usually, getting a number with its fractional part as zero takes long and we stop after 3-4 digits of precision.
The following figure shows Decimal to Octal, Hexadecimal, and Binary Conversion with the same number as an example.
![Decimal to Octal, Hexadecimal, and Binary Conversion](https://www.sanfoundry.com/wp-content/uploads/2024/05/decimal-to-octal-hexadecimal-and-binary-conversion.png)
As can be seen from the figure,
- While converting to octal, hexadecimal, and binary, we divided the number by 8, 16, and 2 respectively, and wrote down the remainders in reverse order as our integer part.
- For the fractional part, we have multiplied with the respective bases and have written them down in the order of our performed multiplication.
Binary, Octal, and Hexadecimal to Decimal Conversion
To convert any number from any other base to decimal, we simply express the number as its product of digits and corresponding radix-powers of its current base and add the obtained values. For example,
- Octal to decimal: – We multiply the digits with powers of 8 according to their positions.
(1456)8 = 1 x 83 + 4 x 82 + 5 x 81 + 6 x 80
= 512 + 256 + 40 + 6
= (814)10 - Binary to decimal: – We multiply the digits with powers of 2 according to their positions.
(100110.101)2 = 1 x 25 + 0 x 24 + 0 x 23 + 1 x 22 + 1 x 21 + 0 x 20 + 1 x 2-1 + 0 x 2-2 + 1 x 2-3
= 32 + 0 + 0 + 4 + 2 + 0 + 0.5 + 0 + 0.125
= (38.625)10 - Hexadecimal to decimal: – We multiply the digits with powers of 16 according to their positions.
(6D4.B0)16 = 6 x 162 + 13 x 161 + 4 x 160 + 11 x 16-1 + 0 x 16-2
= 1536 + 48 + 4 + 0.6875 + 0
= (1748.6875)10
Decimal to Binary Conversion
The steps below should be followed to convert a decimal number into a binary number:
- Step-1: Find the remainder and quotient by dividing the decimal number by 2 because the base for binary number system is 2.
- Step-2: Again divide the quotient by 2 and find the remainder. This step continues till the quotient becomes zero because if quotient is zero then further division by 2 will not be possible.
- Step-3: The remainders obtained after each division will be either 0 or 1 as division by 2 can produce only two possible remainders. Now, after combining the remainders in reverse order we will get the desired binary representation.
Binary to Octal Conversion
For converting a binary number to octal we make use of the fact that all octal digits can be perfectly expressed with 3 binary bits. The steps that we follow are: –
- For the integer part: We make groups of 3 bits beginning from the last bit, moving towards higher bits.
- For fractional part: We begin making groups of 3 bits just after the radix point and move towards the right.
- We then write down the corresponding octal value for each group of those three bits.
For example,- (110111001)2 can be written in octal as: – 1 1 0 | 1 1 1 | 0 0 1 = (671)8
- (011110.010101)2 can be written in octal as: – 0 1 1 | 1 1 0 |.| 0 1 0 | 1 0 1 = (36.25)8
- In case, any group is left with lesser number of bits, more zeroes can be added in front of it (for the integer part) and at the end (for the fractional part), to make that group of 3 bits.
For example, - (11100111.11)2 can be written in octal as: – 1 1|1 0 0 | 1 1 1 |.| 1 1 when regrouped becomes 0 1 1 | 1 0 0 | 1 1 1 |.| 1 1 0 = (347.6)8
Octal to Binary Conversion
To convert from octal to binary system, we write down the corresponding values of each digit of octal in its binary 3-bits form. This is a reverse operation of what we did in the previous section. The following figure shows how to convert a number from octal to binary.
![Octal to Binary Conversion](https://www.sanfoundry.com/wp-content/uploads/2024/05/octal-binary-conversion.png)
As is clear from the figure,
- Each octal digit is converted into its 3-bit binary equivalent and obtained values are written all together to give the binary equivalent of the octal number.
Here is a table to always refer to while converting from octal to binary or vice-versa.
Positional Values(22 21 20) | 4 2 1 | 4 2 1 | 4 2 1 | 4 2 1 | 4 2 1 | 4 2 1 | 4 2 1 | 4 2 1 |
---|---|---|---|---|---|---|---|---|
Binary | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
Octal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
As shown in the table,
- The positional values given by 4 2 1, can be used to calculate binary equivalents of octal numbers by writing 1 for that positional value which contributes to the sum of that digit. For example, 7=4+2+1, so we can write it as 111, etc.
Binary to Hexadecimal Conversion
For converting a number from binary to hexadecimal, we make groups as we did for octal, but instead of 3-bits, we make 4-bit groups. Here are the steps to convert:
- We make groups of 4-bit, from the right-most bit (LSB) to the left-most bit (MSB) for the integer part, and write down the corresponding hexadecimal values for each group.
- For the fractional part, we begin grouping after the radix point and move towards the right.
- Also, we can add zeroes in front of a group (for the integer part) and zeroes to the end of a group (for the fractional part), to make it a 4-bit group.
For example: –
- (1011110011.11101)2 can be written in hexadecimal as: –
0010|1111|0011|.|1110|1000 = (2F3.E8)16 - (11010011.1010)2 can be written in hexadecimal as: –
1101|0011|.|1010 = (D3. A)16
Hexadecimal to Binary Conversion
For hexadecimal to binary conversion, we write down each hexadecimal digit’s 4-bit binary equivalent, and group the results together to give the final converted value. Here is a figure that shows hexadecimal to binary conversion.
![Hexadecimal to Binary Conversion](https://www.sanfoundry.com/wp-content/uploads/2024/05/hexadecimal-to-binary-conversion.png)
As can be seen from the figure,
- Each digit was converted individually from hexadecimal to binary and written together to give the binary form of the hexadecimal number.
Here is a table to refer to while converting a number from hexadecimal to binary and vice-versa.
Positional Values(23 22 21 20) | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 |
---|---|---|---|---|---|---|---|---|
Hexadecimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | Binary | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Hexadecimal | 8 | 9 | A | B | C | D | E | F |
As shown in the table,
- The binary equivalent of hexadecimal digits can be remembered easily by adding the positional values of 8 4 2 1 by using 1 for only those positions, which add up to the sum of that digit. For example, 9=8+0+0+1, hence we write it as 1001.
Hexadecimal to Decimal Conversion
The steps below should be followed to convert a hexadecimal number into a decimal number:
- Step-1: Determine the place value of each digit of the hexadecimal number form LSB to MSB starting with 0. For example:
2 1 0 ← Place value
(9 1 F)16 - Step-2: Multiply each digit by 16 having power equal to its place value. For example, 9 × 162 means hexadecimal digit ‘9’ has ‘2’ as its place value.
- Step-3: Now add all the values obtained after multiplication. The resultant will be the decimal equivalent number. For example, (9 1 F)16 = 9 × 162 + 1 × 161 + F ×160
= 2335
Decimal to Hexadecimal Conversion
The steps below should be followed to convert a decimal number into a hexadecimal number:
- Step-1: Find the remainder and quotient by dividing the decimal number by 16 because the base for hexadecimal number system is 16. If remainder is greater than 9 then the remainder should be represented by an alphabet (For numbers 10, 11, 12, 13, 14, 15 respective alphabets are A, B, C, D, E, F).
- Step-2: Again divide the quotient by 16 and find the remainder. This step continues till the quotient becomes zero because if quotient is zero then division by 16 is not possible.
- Step-3: The remainder obtained after each division will be a number from 0 to 15, as a remainder is always less than the divisor. Now, after combining the remainders together in reverse order we will get the desired hexadecimal representation.
Octal to Hexadecimal Conversion
Octal numbers cannot be directly converted into hexadecimal form. So we convert it to an intermediate decimal or binary form. Using decimal as an intermediate form, our calculations increase, so we use binary for quick conversion. The steps are shown below using an example:
To convert (672.34)8 into hexadecimal:
- 1st step: Convert the number into binary by converting each octal digit individually into its 3-bit binary code: – (110 111 010 . 011 100)
- 2nd step: Group by 4-bits from the right for the integer part and from the left for the fractional part: – (0001) (1011) (1010) . (0111) (0000)
- 3rd step: Write the corresponding hexadecimal digits to each 4-bit group: – (1BA.70)16
Hexadecimal to Octal Conversion
Hexadecimal numbers also need an intermediate form to convert into octal numbers. Here are the steps to follow:
To convert (A2B6.83)16 into octal:
- 1st step: Convert the hexadecimal number into binary form by expanding each digit individually into its 4-bit binary code: – (1010 0010 1011 0110 . 1000 0011)
- 2nd step: From the right group the digits into 3-bits for the integer part and start after the radix point for the fractional part: – (001) (010) (001) (010) (110) (110) . (100) (000) (110)
- 3rd step: Convert each 3-bit group into its equivalent octal digit: – (121266.406)8
Decimal to Octal Conversion
The steps below should be followed to convert a decimal number into an octal number:
- Step-1: Find the remainder and quotient by dividing the decimal number by 8 because the base for octal number system is 8.
- Step-2: Again divide the quotient by 8 and find the remainder. This step continues till the quotient becomes zero because if quotient is zero then division by 8 is not possible.
- Step-3: The remainder obtained after each division will be a number from 0 to 7 because the divisor is always greater than the remainder. Now, the number obtained after combining the remainders in reverse order will be the octal representation of the decimal number.
Octal to Decimal Conversion
The steps below should be followed to convert an octal number into a decimal number:
- Step-1: Determine the place value of each digit of the octal number form LSB to MSB starting with 0. For example:
2 1 0 ← Place value
(3 1 7)8 - Step-2: Multiply each digit by 8 having power equal to its place value. For example, 7 × 80 means octal digit ‘7’ has ‘0’ as its place value.
- Step-3: Now add all the values obtained after multiplication. The resultant will be the decimal equivalent number. For example, (3 1 7)16 = 3 × 82 + 1 × 81 + 7 × 80
= 255
Importance of Number System Conversions
The importance of number system conversions are explained below:
- Decimal number system is the most commonly used number system in real world but computer understands only binary language. So, decimal conversion to binary is required in order to interact with computers.
- Hexadecimal number has base 16. When dealing with large decimal and binary numbers, this number system is used to represent numbers in small form.
- Availability of different number systems and their conversion techniques connect codes, alphabets, digits and symbols together all over the globe.
Key Points to Remember
Here are some key points listed, which are to be remembered in “Number System Conversion”.
- A decimal number can be converted to any base by dividing the integer part by that base repeatedly till the remainder is zero and writing the remainders in reverse order.
- From any base, a number can be converted into decimal form by expanding the number as its digits and radix-power product, followed by adding up the values.
- Binary can be converted into Octal and Hexadecimal by grouping into 3 and 4 bits respectively and writing the corresponding digits.
- Octal or hexadecimal is converted back into binary by expanding each digit’s 3-bit or 4-bit binary codes respectively.
- Octal and Hexadecimal numbers cannot be interconverted directly; they need to be converted first either into decimal or binary.
- For grouping any number, we move from LSB to MSB for the integer part, and for the fractional part, we start grouping after the radix point till the last fractional digit.
- On converting a number from a lower base to a higher one, the number of digits decreases for the integer part and increases for the fractional part.
- On converting from a higher base to a lower one, the number of digits increases for the integer part and decreases for the fractional part.
- Decimal to binary conversion is essential for computer operations, while hexadecimal simplifies the representation of large binary numbers.