This is the correct result of rotating 0x17
in a 32-bit integer: you start with
00000000 00000000 00000000 00010111
and you end up with
10000000 00000000 00000000 00001011
If you would like to rotate an 8-bit number, use uint8_t
instead of int
as the function parameter:
uint8_t rotr(uint8_t value, int shift) {
// No need to multiply by sizeof(value), because the type uint8_t forces it to be 1
return (value >> shift) | (value << 8 - shift));
}