Archlinux

GCC 13.1.1  20230429

2023-07-23 19:59:05 星期日

 


点击查看代码
#include<stdio.h>
#include<stdint.h>

int rightrot( unsigned int x, int n )
{
    uint8_t tmp;

    while( n > 0 )
    {
        tmp = (x & 1) << 7;     // 0000 000x -> x0000 0000
        x = x >> 1;     // xxxx xxxs -> 0xxx xxxx
        tmp = x | tmp;
        n--;
    }

    return tmp;
}


int main()
{
    int x = 129;    // 1000 0001  ->  1100 0000(192)     
    
    int c = rightrot( x, 1 );
    printf("%d\n", c);


    return 0;
}


 


运行截图:

image

输出正确。

 


小白刚学习C语言,代码质量不高,欢迎评论。

posted on 2023-07-23 19:59  语巫  阅读(96)  评论(0)    收藏  举报