Python 十进制字符串转换为二进制字符串
可以使用内置函数 'bin()' 将十进制数转换为二进制数,再去掉前缀 '0b',即可得到二进制字符串。
例如:
dec_str = '10'
bn_str = bin(int(dec_str))[2:]
print(bin_str) # 输出:1010
原文地址: https://www.cveoy.top/t/topic/nKr6 著作权归作者所有。请勿转载和采集!
安全问答是一个知识全球问答,包含丰富的问答知识
可以使用内置函数 'bin()' 将十进制数转换为二进制数,再去掉前缀 '0b',即可得到二进制字符串。
例如:
dec_str = '10'
bn_str = bin(int(dec_str))[2:]
print(bin_str) # 输出:1010
原文地址: https://www.cveoy.top/t/topic/nKr6 著作权归作者所有。请勿转载和采集!