I\'m looking for the fastest way of counting the number of bit transitions in an unsigned int.
unsigned int
If the int contains: 0b0000000000000000000000000000101
0b0000000000000000000000000000101
In C/C++ I would do the following:
unsigned int Transitions(unsigned int value) { unsigned int result = 0; for (unsigned int markers = value ^ (value >> 1); markers; markers = markers >> 1) { if (markers & 0x01) result++; } return result; }