如何将所有位向左旋转,在c中向右旋转最后一位

-2 c bit-manipulation bit

我必须将所有位从x 1位置向左移位,将左边的第一位移位到位位置0(最右边).我想知道我做错了什么,你可以帮助我.

int rotateleft (int x);

int main ()
{      
    int getal,result;
    printf("Enter a number :\n");
    scanf("%i",&getal);
    result=rotateleft(getal);
    printf("result after rotation: %08x", result );
    return 0;
}

int rotateleft (int x)
{
    int rbit;
    rbit = x <<1;
return rbit;
}
Run Code Online (Sandbox Code Playgroud)

Ron*_*Ron 5

来自维基百科:

unsigned int rotl(unsigned int value, int shift) {
    return (value << shift) | (value >> (sizeof(value) * CHAR_BIT - shift));
}
Run Code Online (Sandbox Code Playgroud)