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

代码如下:

#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;
}

你可能感兴趣的:(UI,iostream)