無(wú)符號(hào)的整數(shù)加法莺奸、乘法是mod2^32的加法搁廓、乘法履磨;
證明:
#include "stdafx.h"
#include "iostream"
using namespace std;
int main()
{
unsigned int t = UINT_MAX;
cout << "令t = unsigned int 的最大值 = " << t << endl;
cout << "2^32 = " << pow(2, 32) << endl;
cout << "2^32 - t = " << pow(2, 32) - t << endl;
cout << "由上可得2^32大于unsigned int能表示的最大值\n\n";
cout << "故2^32用unsigned int表示將會(huì)溢出\n\n";
cout << "無(wú)符號(hào)整數(shù)的mod2^32等價(jià)于它們本身\n\n";
cout << "故無(wú)符號(hào)的整數(shù)的加乘為其mod2^32的加乘\n";
return 0;
}
代碼運(yùn)行結(jié)果如下:
令t = unsigned int 的最大值 = 4294967295
2^32 = 4.29497e+09
2^32 - t = 1
由上可得2^32大于unsigned int能表示的最大值
故2^32用unsigned int表示將會(huì)溢出
無(wú)符號(hào)整數(shù)的mod2^32等價(jià)于它們本身
故無(wú)符號(hào)的整數(shù)的加乘為其mod2^32的加乘