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


当前回答

假设。net -

Console.WriteLine(Int32.MaxValue);

其他回答

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

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

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

max_signed_32_bit_num = 1 << 31 - 1;  // alternatively ~(1 << 31)

编译器无论如何都应该优化它。

我更喜欢1 << 31 - 1

0x7fffffff因为你不需要计数fs

Unsigned (pow(2,31)) - 1,因为你不需要<math.h>

永远不要忘记任何类型的最大值:

如果它有32位,最大的可能值将是带有数字1的32位:

结果将是十进制的4294967295:

但是,由于也有负数的表示,4294967295除以2,得到2147483647。

因此,一个32位整数能够表示-2147483647到2147483647

这就是我记住2147483647的方法

在遥远的大草原上,擎天柱三人对着四十个七分咒

2 - To
1 - A
4 - Far
7 - Savannah
4 - Quarter
8 - Optimus
3 - Trio
6 - Hexed
4 - Forty
7 - Septenary