Fastest way to count number of bit transitions in an unsigned int

前端 未结 6 2308
说谎
说谎 2021-02-09 20:31

I\'m looking for the fastest way of counting the number of bit transitions in an unsigned int.

If the int contains: 0b0000000000000000000000000000101

6条回答
  •  佛祖请我去吃肉
    2021-02-09 21:05

    What language?

    I would loop 64 times and then bit shift your number to inspect of the bits, then store the previous bit and compare it to the current one. If it's different, incremember your count.

提交回复
热议问题