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


当前回答

32位,1位符号,31位信息

2^31 - 1 = 2147483647

为什么1 ? 因为第一个是0,所以最大的是count - 1。

编辑cantfindaname88

计数是2^31,但最大的不可能是2147483648(2^31),因为我们是从0开始计数的,而不是1。

Rank   1 2 3 4 5 6 ... 2147483648
Number 0 1 2 3 4 5 ... 2147483647

另一种解释只有3位:1位是符号,2位是信息

2^2 - 1 = 3

下面是所有可能的3位值:(2^3 = 8个值)

1: 100 ==> -4
2: 101 ==> -3
3: 110 ==> -2
4: 111 ==> -1
5: 000 ==>  0
6: 001 ==>  1
7: 010 ==>  2
8: 011 ==>  3

其他回答

最简单的方法是查看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;
}

有趣的是,Int32。MaxValue拥有超过2,147,486,647个字符。

但话说回来,我们有代码完成,

所以我想我们真正需要记住的是Int3<period>M<enter>,这在visual studio中只有6个字符。

更新 出于某种原因,我被否决了。我能想到的唯一原因是他们没有理解我的第一句话。

“Int32。MaxValue最多需要14个字符来输入。 2147,486,647需要输入10或13个字符,这取决于是否使用逗号。

如果你能记住圆周率的整个数字,那么你要找的数字在圆周率的十进制数字1867996680到1867996689的位置

数字字符串2147483647出现在圆周率的十进制数字1,867,996,680。3.14......86181221809936452346214748364710527835665425671614…

来源:http://www.subidiom.com/pi/

如果你碰巧记住了你的ASCII表而不是MaxInt: gh6g = 21 47 48 36 47

这里有一个记忆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太容易了。