Reputation: 1
I'm trying to convert a base64 encoded string to its binary form. Basically "cw==" should return 01100110000. I tried various modules but can't seem to find a suitable one. Any one got any ideas?
thanks! j
Upvotes: 0
Views: 5400
Reputation: 18747
You must first decode your string
from base64 import decodestring
Then you can use format(ord(x), "b")
to produce a binary representation.
my_string = "cw=="
print "".join(format(ord(x), "b") for x in decodestring(my_string))
>> '1110011'
Upvotes: 1