Python By Example

Convert Binary to Hexadecimal

by Jiffin Joachim Gomez on 24th February 2017

This is a simple Python script to convert binary to hexadecimal. The program asks the user to input the binary number, In Python we have built in functions to convert hexadecimal number, just use hex() function to convert any number. So we don't have to worry about the mathematics behind how to convert decimal numbers to hexadecimal.

#Getting input from the user
binary = input("Enter number in Binary Format: ")
temp = int(binary, 2)
print(binary,"in Hexadecimal =",hex(temp)[2:],"\n")
Enter number in Binary Format: 000100101111
000100101111 in Hexadecimal = 12f 
>>> 

Post a comment

Comments

Nothing yet..be the first to share wisdom.