我总是记不住电话号码。我需要一个记忆规则。


当前回答

如果你觉得以10为进制很难记住这个值,试试以2为进制: 1111111111111111111111111111111

其他回答

最简单的方法是查看std::numeric_limits< int >::max()

例如(来自MSDN),

// numeric_limits_max.cpp

#include <iostream>
#include <limits>

using namespace std;

int main() {
   cout << "The maximum value for type float is:  "
        << numeric_limits<float>::max( )
        << endl;
   cout << "The maximum value for type double is:  "
        << numeric_limits<double>::max( )
        << endl;
   cout << "The maximum value for type int is:  "
        << numeric_limits<int>::max( )
        << endl;
   cout << "The maximum value for type short int is:  "
        << numeric_limits<short int>::max( )
        << endl;
}

我是这样记得的…… 在十六进制中,一个数字代表4位,所以4 * 8 = 32,所以最大有符号的32位整型是:

0xFFFFFFFF >> 1 # => 2147483647

试试用Python:

>>> int('1' * 31, base=2)
2147483647

这里有一个记忆2**31,减去1得到最大整数值的助记符。

a = 1, b = 2, c = 3 d = 4 = 5, f = 6 g = 7, 8 h = = 9

Boys And Dogs Go Duck Hunting, Come Friday Ducks Hide
2    1   4    7  4    8        3    6      4     8

我经常使用2到18的幂来记住它们,但即使是我也没有费心去记住2**31。根据需要计算或使用常数,或估计为2G太容易了。

它是231−1(32位,其中1位用于符号)。

如果你想要一个近似值,使用210 = 1024≈103,所以231≈2*109。如果您想手动计算一个精确的值,可以使用平方的求幂来得到232 = 2(25),然后除以2。你只需要平方5次就可以得到232:

2*2 = 4
4*4 = 16
16*16 = 256
256*256 = 25*25*100 + 2*250*6 + 36 = 62500 + 3000 + 36 = 65536
65536*65536 =65000*65000 + 2*65000*536 + 536*536 =  
4225000000 + 130000*536 + (250000 + 3600 + 36*36) =
4225000000 + 69680000 + 250000 + 3600 + 1296 =
4294967296

把这个除以2再减去1得到2147,483,647。如果你不需要所有的数字,只需要前三位有效数字,那么每一步平方的计算都很简单。