Reputation: 23
This seems really simple but I can't figure it out. I have a string of bits in a string format and want to convert it to a binary format. I assumed placing the string inside of the bin() function would work but it doesn't.
string = "01101"
print(bin(string))
Upvotes: 0
Views: 356
Reputation: 80111
It depends what you mean by binary format.
Here's a few examples of what you can do:
>>> int('01101', 2)
13
>>> number = 13
>>> bin(number)
'0b1101'
>>> oct(number)
'0o15'
>>> hex(number)
'0xd'
>>> f'{number:08b}'
'00001101'
Upvotes: 1