Let's call it "<<<"
int32variable <<< numberOfBits
equals
(int32variable << numberOfBits) | (int32variable >> (32 - numberOfBits))
(Assuming << and >> discards overflown bits)
There is such an operator?
Let's call it "<<<"
int32variable <<< numberOfBits
equals
(int32variable << numberOfBits) | (int32variable >> (32 - numberOfBits))
(Assuming << and >> discards overflown bits)
There is such an operator?
There is no primitive operator in C# to do what you're looking for.
Ignoring the performance implications of a method call (if you're doing bitshift operations, you might care), this would be a good candidate for an extension method on Int32.
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.
This is called a bitwise rotation. Other languages have it, but C# does not. See this question for a little more detail, but the gist of it is that your current approach is about as good as you can do.
I don't think that there is for C#. See this page for the list of C# operators: http://msdn.microsoft.com/en-us/library/6a71f45d(vs.71).aspx.
I think that they way you have shown in your question is probably the quickest way to do it. I think that Java may have a shift operator like the one you are after, but not being a Java programer I can't confirm that.