要求:输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。
class Solution:
def getOneCount(self, n):
# write code here
count=0;
for i in range(32):#int占4个字节
if n&1:#进行与操作
count=count+1
n=n>>1#进行位右移,左边补0
return count