# 位运算 # 思路:把该number的左右边的1-1变为0,1后面的0变为1;在于number & 的话就消除一个1,循环消1 即可 def numberof_inbinary(number): count = 0 while number: count += 1 number = (number - 1) & number # 本质是在消除1的过程 return count