程序检测底层数据是two complement(补码)还是one complement(反码)表示

来源:互联网 发布:c语言的运算程序 编辑:程序博客网 时间:2024/05/18 22:08

代码如下:

#include <iostream>

using namespace std;

int CheckComplement()
{
    union
    {
        unsigned int ui;
        signed int si;
    }uComplementChecker;
 
    uComplementChecker.si = -1;
    unsigned int ui = ~0;
 
    return (uComplementChecker.ui == ui) ? 2 : 1;
}

原创粉丝点击