设计一个函数,使给出一个数的原码,能得到该数的补码。
代码如下:
#include <stdio.h>
unsigned short int getbits(unsigned short value); int main(int argc,char *argv[]) { unsigned int short a; printf("input an octal number:"); scanf("%o",&a); printf("result:%o\n",getbits(a)); system("pause"); return 0; }
unsigned short int getbits(unsigned short value) { unsigned int short z; z = value & 0100000; if (z == 0100000) { z = ~value + 1; } else { z = value; } return z; }
|
阅读(3783) | 评论(0) | 转发(0) |