c语言左右循环移位.docx
C语言左右循环移位c语言左右循环移位编写一函数用来实现左右循环移位。函数名为move,调用方法为move (value, n);其中value为要循环 位移的数,n为位移的位数,如n < 0表示为左移;n0为右移;如n = 4表示要右移4位,n = -3表示要左移3位。代码如下:#include unsigned short moveleft(unsigned short , int); unsigned short moveright(unsigned short, int); int main(int argc, char *argv) unsigned short a; int n; printf("input an octal number:");scanf (绘o", &a) ; printf (*input n:); scanf &n) ; if (n > 0) printf (,result:%on,, moveright (a, n); else n = -n;printf (result :%on/z, moveleft (a, n) ; system ("pause") ; unsigned short moveleft(unsigned short value, int n) unsigned short z; z =(value » (16 - n) | (value « n); return z; unsigned short moveright(unsigned short value , int n) unsigned short z; z = (value >> n) | (value << (16 -n); return z;