你确定你没有伪造那个错误信息吗?
编码...
>>> int('10010101101001011011000000001111001110111110000100101000000011111111100000111010111011101111110010001101101001101000100000001100010011000010100000110100100001010110011111101101000101101001011001100110', 2)
939350809951131205472627037306557272273273866819979105965670L
...为我工作。
而且,您的代码的具体示例...
>>> x = 82349832
>>> y = 23432984
>>> z = bin(x) + bin(y)
>>> int(z, 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 2: '0b1001110100010001111000010000b1011001011000111100011000'
0b
...在错误消息中显示问题(即前缀)。
解决方案是使用...剥离前缀
z = bin(x)[2:] + bin(y)[2:]
z = int(z, 2)
...或者,正如 Martijn Pieters 所建议的那样,使用format()
...生成不带前缀的二进制表示
z = format(x, 'b') + format(y, 'b')
z = int(z, 2)
...或者,正如 gnibbler 建议的那样,使用字符串对象的format()
方法在一次调用中完成...
z = '{:b}{:b}'.format(x, y)
z = int(z, 2)