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


当前回答

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

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

0xFFFFFFFF >> 1 # => 2147483647

它有32位,因此可以存储2^32个不同的值。其中一半是负面的。

答案是2147,483,647

最低的是- 2,147,483,648。

(注意这里多了一个负数。)

最好的记忆规则是: 21(神奇的数字!) 47(记住) 48(顺序!) 36(21 + 15,都是魔法!) 47又

记住5对数字也比记住10对数字容易。

这就是我如何记住2147483647的:

214 -因为2.14近似于pi-1 48 = 6*8 64 = 8*8

横向写:

214_48_64_
and insert:
   ^  ^  ^
   7  3  7 - which is Boeing's airliner jet (thanks, sgorozco)

现在你得到了2147483647。

希望这能有所帮助。