简体   繁体   English

将base64编码的字符串转换为二进制

[英]Convert a base64 encoded string to binary

I'm trying to convert a base64 encoded string to its binary form. 我正在尝试将base64编码的字符串转换为其二进制形式。 Basically "cw==" should return 01100110000. I tried various modules but can't seem to find a suitable one. 基本上,“ cw ==“应该返回01100110000。我尝试了各种模块,但似乎找不到合适的模块。 Any one got any ideas? 任何人有任何想法吗?

thanks! 谢谢! j Ĵ

You must first decode your string 您必须先解码您的字符串

from base64 import decodestring

Then you can use format(ord(x), "b") to produce a binary representation. 然后,您可以使用format(ord(x), "b")生成二进制表示形式。

my_string = "cw=="
print "".join(format(ord(x), "b") for x in decodestring(my_string))
>> '1110011'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM