求补码怎么求的...

问题描述:

求补码怎么求的...
#include
#include
void main ()
{
unsigned short int a;
unsigned short int getbits(unsigned short);
printf ("\ninput an octal number:");
scanf ("%o",&a);
printf ("%o\n",getbits(a));
}
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;
}
输入152525怎么会输出25253呢?书上的例子,

程序让你输入的是8进制数字,所以152525是八进制的
化成二进制为1101 0101 0101 0101
判断第一位是1
z等于 取反+1 = 10 1010 1010 1010 +1 在打印成8进制就是25253了谢谢,不过~value后,不是把符号位也反了吗? .... 越弄越晕啊,,,