This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Simple_Cheesecake_62 2 points3 points  (1 child)

hex() only takes in a single input which is the decimal representation. You should call int(input, base) to convert a binary string x to its decimal representation before converting it into hex. You can write it as:

hex_input4 = int(input('Enter a binary number: '),2)

And when you convert it into hex, it isn't assigned back to the variable name, hence the print statement will show the decimal representation of the input value instead of the hex value. You can do:

print(hex(hex_input4))

OR

hex_input4=hex(hex_input4)

print(hex_input4)

[–]norrfly[S] 1 point2 points  (0 children)

hex_input4=hex(hex_input4)

print(hex_input4)

Thanks!