请输入一个十进制正整数,利用Python编程输出其对应的二进制表示中有几个数字1?

【算法代码】

x=int(input("Enter an integer:"))
s=0
while x:
    if x&1==1:
        s=s+1
    x=x>>1

print(s)

猜你喜欢

转载自blog.csdn.net/hnjzsyjyj/article/details/121110456