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


当前回答

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

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

+2147483647到-2147483648

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

+9223372036854775807 至 -9223372036854775808

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

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

其他回答

我能想到的最正确的答案是Int32.MaxValue。

假设。net -

Console.WriteLine(Int32.MaxValue);

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

这就是我记住2147483647的方法

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

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

大约是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