图一为右移4位。图二为左移4位。
#include "stdio.h" void main() { unsigned short moveright(unsigned short,int); unsigned short moveleft(unsigned short,int); unsigned short a; int n; printf("\ninput an octal number:"); scanf("%o",&a); printf("input n:"); scanf("%d",&n); if (n>0) { moveright(a,n); printf("result:%o\n",moveright(a,n)); } else { n=-n; moveleft(a,n); printf("result:%o\n",moveleft(a,n)); } printf("\n2013304112"); } unsigned short moveright(unsigned short value,int n) { unsigned short z; z=(value>>n)|(value<<(16-n));; return(z); } unsigned short moveleft(unsigned short value,int n) { unsigned short z; z=(value>>(16-n)|(value<<n));; return(z); }