I'm having a little trouble writing my code to rotate my hexadecimal digits right. Below is a function I wrote, where, if you call on it, passing it like so: rotr(0x12345678, 4), it should return 0x81234567. Instead, it's only returning 7 digits (as opposed to eight, like in the original value = 0x12345678).
Can someone please help me understand what is going on in the bit level? I'm having trouble understanding why my current code is returning 0x123456f, instead of 0x81234567. Thanks in advance!
Edit: is it because I'm shifting 0x12345678 too early? I'm mainly trying to figure out why only seven digits return back, as opposed to eight.
unsigned int rotr(unsigned int x, int n) {
int i; //iterate for loop
unsigned int y; //masked last bit
unsigned int z; //final result
for (i=1; i<=n; i++) {
y = x & 0x1; //isolates last bit
x = x >> 1; //shift right 1
z = x | (y << (sizeof(x)-1)); //shifts mask back to first slot; OR
//it with x
}
return z;
}