M1:
func hammingWeight(_ n:uint) -> Int {
var count = 0
var tmpn = n
while tmpn > 0 {
let tmp = tmpn & 1
if tmp == 1 { count+=1 }
tmpn = tmpn >> 1
}
return count
}
M2:
https://www.jianshu.com/p/4c531932cb9e
中的方法二(相比M1,执行时间会稍显长点,思路值得学习)