No loops are allowed. The only operators allowed are ~ & ^ | + << >> !
Rotate x to the right by 4.
Examples: rotate4(0x87654321) = 0x18765432
Max ops: 12
int rotate4(int x){
CODE
I have
int rotate4(int x){
return (x << 28) | (x >> 4);
This is outputting a negative number that seems to be correct, but negative.
Test: Answer should be 134217728[0x80000000]
My Answer is -134217728[0xf8000000]
My though process is:
x << moves the 4 LSB code to the left 28 spaces meaning the 4 LSB will be left in the MSB position.
x >> 4 drops off the 4 LSB so that the 4 MSB are 0s.
Is my code producing the wrong result because it is right shifting arithmetically?