方法一:
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
方法二:
def NumberOf1(n):
# write code here
return bin (n).replace ("0b", "").count ("1") if n >= 0 else bin (2 ** 32 + n).replace ("0b", "").count ("1")
a =89
b = NumberOf1(a)