I'm having trouble figuring out what exactly I'm missing in this Byte reversal method. For example is should take 0x01020304 and flip the bits to 0x04030201.
I've attached my output giving the errors and here is my code:
/*
* reverseBytes - reverse the bytes of x
* Example: reverseBytes(0x01020304) = 0x04030201
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 25
* Rating: 3
*/
int reverseBytes(int x) {
printf("x is %d\n", x);
x = (x & 0x7FFFFFFF );
printf("x is %d\n", x);
x = ((x&0xF0) >>4) | ((x&0x0F) << 4);
x = ((x&0xCC) >>2) | ((x&0x33) << 2);
return ((x&0xAA) >>1) | ((x&0x55) << 1);
return x;
}
I can't figure out what I'm missing/what needs fixing this is as far as I can get. I can't modify the method name or parameter types and can't use loops/conditionals. Any input/help would be appreciated!