package main
import"fmt"funchammingWeight(num uint32)int{
numNew :=int(num)
res :=0for; numNew >0;{
res +=int(numNew)&1
numNew >>=1}return res
}funcmain(){
fmt.Println(hammingWeight(11))}
Python
classSolution:defhammingWeight(self, n:int)->int:
res =0while n:
res += n &1
n >>=1return res
if __name__ =="__main__":
solution = Solution()print(solution.hammingWeight(11))
C#
publicclassSolution{publicintHammingWeight(uint n){int res =0;while(n >0){
res +=(int)n &1;
n >>=1;}return res;}}classProgram{staticvoidMain(string[] args){Solution solution =newSolution();
Console.WriteLine(solution.HammingWeight(11));}}