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


当前回答

它是2147483647。最简单的记忆方法就是纹身。

其他回答

最大负值(32位):-2147483648 (1 << 31)

最大正(32位)值:2147483647 ~(1 << 31)

记忆:“醉酒又好色”

drunk ========= Drinking age is 21
AK ============ AK 47
A ============= 4 (A and 4 look the same)
horny ========= internet rule 34 (if it exists, there's 18+ material of it) 

21 47 4(years) 3(years) 4(years)
21 47 48       36       48

Int32意味着你有32位可用来存储你的数字。最高位是符号位,这表示数字是正还是负。所以正数和负数都有2^31位。

如果0是正数,则得到(前面提到过)的逻辑范围

+2147483647到-2147483648

如果你认为这太小了,请使用Int64:

+9223372036854775807 至 -9223372036854775808

你为什么要记住这个号码?在代码中使用?您应该始终使用Int32。MaxValue或Int32。因为这些是静态值(在.net核心中),因此使用起来比用代码创建一个新的int更快。

我的陈述:如果能记住这个数字。你这是在炫耀!

在Objective-C (iOS和OSX)中,只需要记住这些宏:

#define INT8_MAX         127
#define INT16_MAX        32767
#define INT32_MAX        2147483647
#define INT64_MAX        9223372036854775807LL

#define UINT8_MAX         255
#define UINT16_MAX        65535
#define UINT32_MAX        4294967295U
#define UINT64_MAX        18446744073709551615ULL

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

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

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

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