codescracker


python

Python Program to Convert Octal to Hexadecimal



« Previous Program Next Program »


Convert Octal to Hexadecimal in Python

To convert octal to hexadecimal number in python, you have to ask from user to enter a number in octal format and start converting the given number into hexadecimal format just by using the function hex() as shown here in the program given below.

Python Programming Code to Convert Octal to Hexadecimal

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

# Python Program - Convert Octal to Hexadecimal
		
while True:
	print("Enter 'x' for exit.")
	octal = input("Enter number in Octal Format: ")
	if octal == 'x':
		break
	else:
		dec = str(int(octal, 8))
		decm = int(dec)
		print(octal,"in Hexadecimal =",hex(decm),"\n")

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

python convert octal to hexadecimal

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