Skip to content

Commit

Permalink
Create Program to Convert Hexadecimal Number to Binary.py
Browse files Browse the repository at this point in the history
  • Loading branch information
callmebvk authored Oct 13, 2024
1 parent 809aecf commit 6bd32bf
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Python/Program to Convert Hexadecimal Number to Binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Python3 program to convert
# Hexadecimal number to Binary

# Function to convert
# Hexadecimal to Binary Number
def HexToBin(hexdec):

for i in hexdec:
if i == '0':
print('0000', end = '')
elif i == '1':
print('0001', end = '')
elif i == '2':
print('0010', end = '')
elif i == '3':
print('0011', end = '')
elif i == '4':
print('0100', end = '')
elif i == '5':
print('0101', end = '')
elif i == '6':
print('0110', end = '')
elif i == '7':
print('0111', end = '')
elif i == '8':
print('1000', end = '')
elif i == '9':
print('1001', end = '')
elif i == 'A' or i == 'a':
print('1010', end = '')
elif i == 'B' or i == 'b':
print('1011', end = '')
elif i == 'C' or i == 'c':
print('1100', end = '')
elif i == 'D' or i == 'd':
print('1101', end = '')
elif i == 'E' or i == 'e':
print('1110', end = '')
elif i == 'F' or i == 'f':
print('1111', end = '')
elif i == '.':
print('.', end = '')
else:
print("\nInvalid hexadecimal digit " +
str(hexdec[i]), end = '')

# Driver code
if __name__=="__main__":

# Get the Hexadecimal number
hexdec= "1AC5";

# Convert HexaDecimal to Binary
print("Equivalent Binary value is : ",
end = '')
HexToBin(hexdec)

# This code is contributed by baliraje_kalyane

0 comments on commit 6bd32bf

Please sign in to comment.