public static IEnumerable<int> GetSetBitPositions(uint value) { // Once value becomes zero, the remainder of the loop can be short-cut for (int x = 0; value != 0; x++, value >>= 1) { if ((value & 1) == 1) yield return x; } }