如何用C语言把有符号数十进制的二进制显示出来?

如何用C语言把有符号数十进制的二进制显示出来?从左往右数第一位表示符号。各位大神帮帮忙啦~~~
要求输出都是16位的,比如输入-1输出1111111111111111
;输入255输出0000000011111111

//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
int main(void){
    int n;
    unsigned f=1<<sizeof(int)*8-1;
    printf("Input n(int)...\nn=");
    scanf("%d",&n);
    printf("%d(10) = ",n);
    while(printf("%d",n&f || 0 ),f>>=1);
    printf("(2)\n");
    return 0;
}

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网