将base64编码的字符串转换为二进制 [英] Convert a base64 encoded string to binary
本文介绍了将base64编码的字符串转换为二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将base64编码的字符串转换为其二进制形式.基本上"cw ==应该返回01100110000.我尝试了各种模块,但似乎找不到合适的模块.任何人有任何想法吗?
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?
谢谢! j
推荐答案
您必须先对字符串进行解码
You must first decode your string
from base64 import decodestring
然后您可以使用format(ord(x), "b")
生成二进制表示形式.
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'
这篇关于将base64编码的字符串转换为二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文