C# bitwise rotate left and rotate right

Prithis picture Prithis · May 1, 2009 · Viewed 41.2k times · Source

What is the C# equivalent (.NET 2.0) of _rotl and _rotr from C++?

Answer

Joseph picture Joseph · May 1, 2009

Is this what you are trying to do?

Jon Skeet answered this in another site

Basically what you want is

(for left)

(original << bits) | (original >> (32 - bits))

or

(for right)

(original >> bits) | (original << (32 - bits))

Also, as Mehrdad has already suggested, this only works for uint, which is the example that Jon gives as well.