Search code examples
c#.netbit-shift

Is there any C# bitwise shift operator that moves the overflown bits to the other tip of the variable?


Let's call it "<<<"

int32variable <<< numberOfBits

equals

(int32variable << numberOfBits) | (int32variable >> (32 - numberOfBits))

(Assuming << and >> discards overflown bits)

There is such an operator?


Solution

  • That would be a called a bit rotate and C# does not have such an operator.

    Here's an interesting post: Is there a way to perform a circular bit shift in C#?

    Note that your int32integer should be of type uint (unsigned int).

    I believe bit rotate is an instructions in the Intel instruction set but as far as I know the CLR does not have bit rotate instructions.