AcWing模板:
求n的第k位数字: n >> k & 1
返回n的最后一位1/最右边:lowbit(n) = n & -n
活动 - AcWing
def lowbit(x):
return x & -x
def main():
n = int(input())
nums = [int(x) for x in input().split()]
for x in nums:
res = 0
while x:
x -= lowbit(x)
res += 1
print(res, end=" ")
main()
小总结:
原码, 反码, 补码:
原码->反码: 符号位不变