Qualcomm Interview Question

The first interview - Calculate the set bits of a number.

Interview Answer

Anonymous

May 6, 2017

2 ways I've seen are to use bitset or iterate with the inverted negative. int n = 31; bitset bs = n; int t = bs.count(); int r = 0; while (n) { n &= ~- n; r++; } return r;