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


当前回答

你会发现在二进制中Int32的最大值是11111111111111111111111111111111111111111 但以10为基数,你会发现它是2147483647或2^31-1或Int32。MaxValue

其他回答

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

2147483647

以下是你需要记住的:

是20亿。 接下来的三个三胞胎是这样增加的:100秒,400秒,600秒 第一个和最后一个三联体需要加3,这样它们就会四舍五入到50(例如147 + 3 = 150 & 647 + 3 = 650) 第二个三联数需要减去3才能四舍五入到80(例如483 - 3 = 480)

因此是2,147,483,647

最简单的方法是查看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;
}
2^(x+y) = 2^x * 2^y

2^10 ~ 1,000
2^20 ~ 1,000,000
2^30 ~ 1,000,000,000
2^40 ~ 1,000,000,000,000
(etc.)

2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
2^7 = 128
2^8 = 256
2^9 = 512

2^31 (signed int max)等于2^30(约10亿)乘以2^1(2)也就是20亿。2^32等于2^30 * 2^2,大约是40亿。这种近似方法甚至可以精确到2^64左右(误差增长到15%左右)。

如果你需要一个确切的答案,那么你应该打开计算器。

方便的字对齐容量近似:

2^16 ~= 64千// uint16 2^32 ~= 40亿// uint32, IPv4, unixtime 2^64 ~= 16 quintillion(又名160亿billion或1600万trillion) // uint64, "bigint" 2^128 ~= 256quintillion quintillion(又名256trillion trillion万亿)// IPv6, GUID

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

答案是2147,483,647

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

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