NVIDIA Interview Question

Write a function in c that counts the number of ones in a variable?

Interview Answer

Anonymous

Jan 4, 2011

//my input is x; int sum=0; While (X !=0){ sum += X & 0x01 X = X >> 1; } return sum;

1