程序中数字取反结果公式

~n = -(n+1)

验证代码

#include<iostream>
using namespace std;
int main()
{
    int i=0;
    for(i=0;i<100;i++)
    {
         cout<<"("<<~i<<" "<<-(i+1)<<") ";
         if((i+1)%10==0)
                cout<<endl;
    }

    return 0;
}

负数在计算机中以补码的形式存储

数字的取反操作与数字的反码是不同的概念

posted on 2016-08-05 14:57  懒惰的码农  阅读(348)  评论(0编辑  收藏  举报

导航