Given a MATLAB uint32 to be interpreted as a bit string, what is an efficient and concise way of counting how many nonzero bits are in the string?
I have a working
I'm reviving an old thread here, but I ran across this problem and I wrote this little bit of code for it:
distance = sum(bitget(bits, 1:32));
Looks pretty concise, but I'm scared that bitget is implemented in O(n) bitshift operations. The code works for what I'm going, but my problem set doesn't rely on hamming weight.