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; }
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; }
/// <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; }