Answer the question
In order to leave comments, you need to log in
How to perform a right bit rotation in C#?
Hello! I am writing a program in C#. There is a number that takes values from 0 to 255 (type - Byte; 8 bits), in which you need to perform a cyclic bit shift to the right. Accordingly, after the shift, you should get a number from 0 to 255.
I found this code:
int shr(int a, int s) {
return (a>>s) | (a<<32-s);
}
Answer the question
In order to leave comments, you need to log in
Well of course they WILL exceed 255! First, the parameters and return value are int, and you need char. Secondly, the data length is explicitly specified as 32 bits.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question