python - python中如何将二进制转换为字符串?

标签 python python-3.x string binary

我一直在尝试将我的二进制文件转换为 python 中的字符串。根本就没有想出任何解决办法。有人有主意吗?下面是我如何将上述字符串转换为二进制的代码。不知道有用吗?

def binary_converter(string):
   for character in string:
        print(bin(ord(character))[2:].zfill(8))

binary_converter("Hello World!")

最佳答案

将其转换为字符串的最简单方法是str.decode()。例如,b"binary code".decode() 将返回字符串。

关于python - python中如何将二进制转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57025763/

相关文章:

java - 在字符串列表中搜索

java - 如果 HashMap 包含key(字符串的任何部分)

python - Pycharm (Ubuntu) 程序无法打开

python - 无法使用 python 连接到 Interactive Brokers

python - Biopython 类实例 - Entrez.read : I don't know how to manipulate the output 的输出

python-3.x - matplotlib 在 Seaborn 下设置小刻度

javascript - Python 将 JavascriptSerializer 转换为日期时间?

python-3.x - 使用 python-opencv 多线程时是否释放了 GIL?

python - NumPy loadtxt()

C++ 在输入中查找字符串并使用运算符