Skip to content

Tag: counting

Fast way of counting non-zero bits in positive integer

I need a fast way to count the number of bits in an integer in python. My current solution is but I am wondering if there is any faster way of doing this? PS: (i am representing a big 2D binary array as a single list of numbers and doing bitwise operations, and that brings the time down from hours