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


当前回答

什么意思?应该很容易记住它是2^32。 如果你想要一个规则来记住这个数字的值,一个方便的经验法则是在二进制和十进制之间转换:

2^10 ~ 1000

这意味着2^20 ~ 1,000,000

2^30 ~ 10亿

2^31的两倍大约是20亿,2^32的两倍是40亿。

这是对任何二进制数进行粗略估计的一种简单方法。二进制中的10个0变成十进制中的3个0。

其他回答

在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

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

它很容易记住。在十六进制中,1位是4位。因此,对于unsigned int,将0x和8 fs (0xffffffff)写入Python或Ruby shell中,以10为基数获得值。如果需要带符号的值,请记住最高位用作符号。所以你必须把它排除在外。您只需要记住,后面三位是1,第四位是0的数字等于7,所以将0x7fffffff写入Python或Ruby shell中。你也可以写0x100000000 - 1和0x80000000 - 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