Given a Hexadecimal number, the task is to convert it into an Octal number.
Input: Hexadecimal = 1AC Output: Binary = 0654 Explanation: Equivalent binary value of 1: 0001 Equivalent binary value of A: 1010 Equivalent binary value of C: 1100 Grouping in terms of 3: 000 110 101 100 Equivalent octal value of 000: 0 Equivalent octal value of 110: 6 Equivalent octal value of 101: 5 Equivalent octal value of 100: 4 Input: Hexadecimal = 5D1F Output: Octal = 56437
A hexadecimal number is a positional numeral system with a radix, or base, of 16 and uses sixteen distinct symbols.
An octal number or oct for short is the base-8 number and uses the digits 0 to 7. Octal numerals can be made from binary numerals by grouping consecutive binary digits into groups of three (starting from the right).
Steps of Conversion
- Find the equivalent binary number for each digit of the given hexadecimal number. Add 0’s to the left if any of the binary equivalent is shorter than 4 bits.
- Separate the binary digits into groups, each containing 3 bits or digits from right to left. Add 0s to the left, if the last group contains less than 3 bits.
- Find the octal equivalent for each binary group.
Below is the implementation of the above approach:
- Program to Convert Octal Number to Binary Number
- Convert a binary number to octal
- Program for Octal to Decimal Conversion
- Program for Decimal to Octal Conversion
- Program for Hexadecimal to Decimal
- Convert Hexadecimal value String to ASCII value String
- Convert a binary number to hexadecimal number
- Octal literals in C
- Octal numbers in c
- Convert C/C++ program to Preprocessor code
- Python program to convert floating to binary
- Check if Decimal representation of an Octal number is divisible by 7
- Decimal to octal conversion with minimum use of arithmetic operators
- Python program to convert decimal to binary number
- Count Hexadecimal Number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Animesh_Gupta