int x = 2; x = rotateInt('L', x, 1); // should return 4 x = rotateInt('R', x, 3); // should return 64 Here is the code, can someone check it and let me know what the error is?
Compilation is successful, but it says Segmentation Fault when I execute it.
int rotateInt(char direction, unsigned int x, int y) { int i; for(i = 0; i < y; i++) { if(direction == 'R') { if((x & 1) == 1) { x = x >> 1; x = (x ^ 128); } else x = x >> 1; } else if(direction == 'L') { if((x & 128) == 1) { x = x << 1; x = (x ^ 1); } else x = x << 1; } } return x; }