norbert78
New User
Dec 27, 2010, 1:40 PM
Post #1 of 3
(1143 views)

(efficiently) calculate hamming weight of bit vector

Can't Post


Hello, hope you all had a wonderful Christmas and are enjoying your holidays. I used my time to get into some perl programming around some crypto algorithms. In the course of this I came to the following question: I have a vector of bits like vec( $bitf, $j,1); Now I need to calculate the hamming weight, i.e. the number of 1's in the vector. To do this, I'm currently running thru a loop and look at each bit of the vector using an if statement. It works but it is also horribly slow (unfortunately my vector is pretty long). Does anybody of you have an idea how I can get the hamming weight more efficiently? Thx Norbert
