Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在编写一个读取整数并显示其二进制表示的python程序时遇到问题,没有乘法或除法?所以它应该像整数5一样转换成101 ..任何人都可以帮忙吗?非常感谢!
print(bin(5)) # yes, it's this easy
你可以bin这样计算:
bin
def bin2(x): binary_digits = [] while x: binary_digits.append(x & 1) x >>= 1 return "".join(str(digit) for digit in reversed(binary_digits))