codescracker


python

Python Program to Convert Hexadecimal to Octal



« Previous Program Next Program »


Convert Hexadecimal to Octal in Python

To convert hexadecimal to octal number in python, you have to ask from user to enter any number in hexadecimal number system to convert that number into octal number system as shown in the program given below.

Python Programming Code to Convert Hexadecimal to Octal

Following python program ask from user to enter any hexadecimal number to convert the number in octal format:

# Python Program - Convert Hexadecimal to Octal

print("Enter 'x' for exit.");
hexdec = input("Enter a number in Hexadecimal Format: ");
if hexdec == 'x':
    exit();
else:
    dec = int(hexdec, 16);
    print(hexdec,"in Octal =",oct(dec));

Here is the sample run of the above Python program demonstrating how to convert hexadecimal number to octal number:

hexadecimal to octal python

Now enter a number that is in hexadecimal form and then to convert it in octal form, just press enter key to see the same number in octal as shown here:

convert hexadecimal to octal python

Here is the screenshot of the same program written and run directly on python shell:

python convert hexadecimal to octal

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »








Tools
Calculator

Quick Links
Signup - Login - Give Online Test