示例#1
0
        public static UInt24 BitRotR(this UInt24 value, int rotations)
        {
            bool loBitSet;

            for (int x = 1; x <= (rotations % 24); x++)
            {
                loBitSet = value.CheckBits(Bits.Bit00);

                value >>= 1;

                if (loBitSet)
                    value = value.SetBits(Bits.Bit23);
                else
                    value = value.ClearBits(Bits.Bit23);
            }

            return value;
        }
示例#2
0
        public static ulong BitRotR(this ulong value, int rotations)
        {
            bool loBitSet;

            for (int x = 1; x <= (rotations % 64); x++)
            {
                loBitSet = value.CheckBits(Bits.Bit00);

                value >>= 1;

                if (loBitSet)
                    value = value.SetBits(Bits.Bit63);
                else
                    value = value.ClearBits(Bits.Bit63);
            }

            return value;
        }
示例#3
0
        /// <summary>
        /// Performs rightwise bit-rotation for the specified number of rotations.
        /// </summary>
        /// <param name="value">Value used for bit-rotation.</param>
        /// <param name="rotations">Number of rotations to perform.</param>
        /// <returns>Value that has its bits rotated to the right the specified number of times.</returns>
        /// <remarks>
        /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native
        /// .NET bit shift operators. As a result bits may actually appear to rotate left on little-endian
        /// architectures.
        /// </remarks>
        public static short BitRotR(this short value, int rotations)
        {
            bool loBitSet;

            for (int x = 1; x <= (rotations % 16); x++)
            {
                loBitSet = value.CheckBits(Bits.Bit00);

                value >>= 1;

                if (loBitSet)
                    value = value.SetBits(Bits.Bit15);
                else
                    value = value.ClearBits(Bits.Bit15);
            }

            return value;
        }
示例#4
0
        public static ulong BitRotL(this ulong value, int rotations)
        {
            bool hiBitSet;

            for (int x = 1; x <= (rotations % 64); x++)
            {
                hiBitSet = value.CheckBits(Bits.Bit63);

                value <<= 1;

                if (hiBitSet)
                    value = value.SetBits(Bits.Bit00);
            }

            return value;
        }
示例#5
0
        /// <summary>
        /// Performs rightwise bit-rotation for the specified number of rotations.
        /// </summary>
        /// <param name="value">Value used for bit-rotation.</param>
        /// <param name="rotations">Number of rotations to perform.</param>
        /// <returns>Value that has its bits rotated to the right the specified number of times.</returns>
        /// <remarks>
        /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native
        /// .NET bit shift operators. As a result bits may actually appear to rotate right on little-endian
        /// architectures.
        /// </remarks>
        public static int BitRotL(this int value, int rotations)
        {
            bool hiBitSet;

            for (int x = 1; x <= (rotations % 32); x++)
            {
                hiBitSet = value.CheckBits(Bits.Bit31);

                value <<= 1;

                if (hiBitSet)
                    value = value.SetBits(Bits.Bit00);
            }

            return value;
        }
示例#6
0
        public static UInt24 BitRotL(this UInt24 value, int rotations)
        {
            bool hiBitSet;

            for (int x = 1; x <= (rotations % 24); x++)
            {
                hiBitSet = value.CheckBits(Bits.Bit23);

                value <<= 1;

                if (hiBitSet)
                    value = value.SetBits(Bits.Bit00);
            }

            return value;
        }
示例#7
0
        public static ushort BitRotL(this ushort value, int rotations)
        {
            bool hiBitSet;

            for (int x = 1; x <= (rotations % 16); x++)
            {
                hiBitSet = value.CheckBits(Bits.Bit15);

                value <<= 1;

                if (hiBitSet)
                    value = value.SetBits(Bits.Bit00);
            }

            return value;
        }