Ejemplo n.º 1
0
        public static int RotateRightThroughCarry(
            int value,
            int bitCount,
            ref bool carry)
        {
            var bitMaskUpToEnd = BitMath.CreateBitmaskUpTo(bitCount);
            var bitMaskAtMsb   = BitMath.CreateBitmaskAt(bitCount - 1);

            value &= bitMaskUpToEnd;

            var remaining = value >> 1;
            var carried   = carry ? bitMaskAtMsb : 0;

            carry = (value & 1) == 1;
            return((remaining | carried) & bitMaskUpToEnd);
        }
Ejemplo n.º 2
0
 public static int CreateBitmaskUpTo(int bitCount)
 => BitMath.CreateBitmaskAt(bitCount) - 1;