GSF.BitMath.GetSetBitPositions C# (CSharp) Method

GetSetBitPositions() public static method

Returns the bit position for every bit that is set in the provided value. Bit positions are defined as 0-31;
public static GetSetBitPositions ( uint value ) : IEnumerable
value uint
return IEnumerable
        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;
            }
        }

Same methods

BitMath::GetSetBitPositions ( ulong value ) : IEnumerable