for x in numbers: # numbers is a list of int
b = bin(x)
#print b # e.g. String 0b1011100101
b = b.replace('0', 'x')
b = b.replace('1', '0')
b = b.replace('x', '1')
b = b.replace('1b', '0b')
#print b # String 0b0100011010
print int(b, 2) # the decimal representation
哈。刚刚发现python
bin()
返回一个字符串!所以我们可以玩得开心点!
只需对0xFF使用the XOR operator ^{} :
如果需要使用大于一个字节的值,可以从值的^{} method 创建掩码:
相关问题 更多 >
编程相关推荐