If you have the binary number 10110 how can I get it to return 5? e.g a number that tells how many bits are used? There are some likewise examples listed below:
int CountBits(uint value) { for (byte i = 32; i > 0; i--) { var b = (uint)1 << (i - 1); if ((value & b) == b) return i; } return 0; }