In: Computer Science
write a python code to Determine the binary and decimal representations of the following hexadecimal numbers. Store answers in the appropriate variables in the .py file.
(a) 0xfca1
(b) 0xc4d8
# Python code to convert
#Hexadecimal to decimal
#Hexadecimal to binary
# taking hexadecimal input from user
value = input("Please enter a string:\n")
# Code to convert hex to Decimal
n = int(value[2:], 16)
# Printing the Decimal Representation of
Hexadecimal
print ("Decimal Representation of ",value," is ",str(n))
# Code to convert Decimal to binary
binaryString = " "
while n > 0:
binaryString = str(n % 2) + binaryString
n = n >> 1
result = binaryString
# Printing the Binary Representation of
Hexadecimal
print ("Binary representation of ",value," is ",str(result))
Screenshot Code:
Output: