#include <stdio.h>
unsigned short int getbits(unsigned short value,int n1,int n2);
int main(int argc,char *argv[])
{
unsigned short int a;
int n1,n2;
printf("input an octal number:");
scanf("%o",&a);
printf("input n1,n2:");
scanf("%d,%d",&n1,&n2);
printf("result:%o\n",getbits(a,n1,n2));
system("pause");
return 0;
}
unsigned short int getbits(unsigned short value,int n1,int n2)
{
unsigned short int z;
z = ~0;
z = (z >> n1) & (z << (16-n2));
z = value & z;
z = z >> (16 - n2);
return z;
}
|