예제 #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);
        }
예제 #2
0
 public static int CreateBitmaskUpTo(int bitCount)
 => BitMath.CreateBitmaskAt(bitCount) - 1;