Issue
sample input: B15 sample output: B15 in binary = 1011000010101
I've tried
a = input()
print(bin(a))
Solution
The hexadecimal number 0xB15 = 2837 has the binary representation 0b101100010101. So if your input is a hexadecimal number, you need to tell Python to convert the string "B15"
which comes out of input()
into the hexadecimal number 0xB15
, also known as the decimal number 2837
, before you can convert it into binary for output.
BASE = 16
a = int(input(), BASE)
print(bin(a)[2:]) # Cut of the first two characters '0b'
Answered By - Anaphory
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.