求助:关于原码、反码、补码
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
short b=-32768;
int i=-2147483648;
cout<<~b<<endl;
cout<<~i<<endl;
cout<<-b<<endl;
cout<<-i<<endl;
return 0;
}
输出结果为: 为什么对short和int取反结果不同呢? 按照我的理解,short的结果应该也为-32768啊。
b的补码表示为1000 0000 0000 0000 求补运算应该也为1000 0000 0000 0000
所以我认为结果应该是-32768。 int的结果和我想象的一样。 求解答。