2024-04-24 00:26:52 发布
网友
我用的是我看到的答案。你知道吗
我的职能是
def to_bin(s): return ' '.join(format(x, 'b') for x in bytearray(s))
它工作得非常好,直到我尝试转换“%”字符,我得到了输出:
>>>to_bin('%') '100101'
而我的预期结果是:
>>>to_bin('%') '0100101'
你们有什么解决办法吗?你知道吗
提前谢谢。你知道吗
只需将格式说明符改为用零填充七个字符:
def to_bin(s): return ' '.join(format(x, '07b') for x in bytearray(s))
只需将格式说明符改为用零填充七个字符:
相关问题 更多 >
编程相关推荐