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


当前回答

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

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

其他回答

大约是2.1 * 10^9。不需要知道确切的2^{31}- 1 = 2,147,483,647。

C

你可以在C语言中找到它:

#include <stdio.h>
#include <limits.h>

main() {
    printf("max int:\t\t%i\n", INT_MAX);
    printf("max unsigned int:\t%u\n", UINT_MAX);
}

给出(好吧,没有,)

max int:          2,147,483,647
max unsigned int: 4,294,967,295

C + 11 +

std::cout << std::numeric_limits<int>::max() << "\n";
std::cout << std::numeric_limits<unsigned int>::max() << "\n";

Java

你也可以用Java得到这个:

System.out.println(Integer.MAX_VALUE);

但是请记住,Java整数总是有符号的。

Python 2

Python有任意的精确整数。但在python2中,它们被映射为C整数。所以你可以这样做:

import sys
sys.maxint
>>> 2147483647
sys.maxint + 1
>>> 2147483648L

所以当整数大于2^31 -1时,Python会切换为long

在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

在C语言中,在#include <stdint.h>后使用INT32_MAX。 在c++中,在#include <cstdint>后使用INT32_MAX。

或INT_MAX平台特定的大小或UINT32_MAX或UINT_MAX unsigned int。参见http://www.cplusplus.com/reference/cstdint/和http://www.cplusplus.com/reference/climits/。

或运算符(int)。

不要把它看成一个大数字,试着把它分解,然后寻找相关的想法。例如:

斯诺克的最大击球次数为2次(最大击球次数为147次) 4年(48个月) 3年(36个月) 4年(48个月)

上述适用于最大的负数;正的是- 1。

也许上面的分类对你来说不会再令人难忘了(它并不令人兴奋!),但希望你能想出一些令人难忘的主意!

最大负值(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