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


当前回答

max_signed_32_bit_num = 1 << 31 - 1;  // alternatively ~(1 << 31)

编译器无论如何都应该优化它。

我更喜欢1 << 31 - 1

0x7fffffff因为你不需要计数fs

Unsigned (pow(2,31)) - 1,因为你不需要<math.h>

其他回答

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

答案是2147,483,647

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

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

如果你碰巧记住了你的ASCII表而不是MaxInt: gh6g = 21 47 48 36 47

我在c#中做了几个天才的方法,你可以在你的生产环境中利用:

public static int GetIntMaxValueGenius1()
{
    int n = 0;
    while (++n > 0) { }
    return --n;
}

public static int GetIntMaxValueGenius2()
{
    int n = 0;
    try
    {
        while (true)
            n = checked(n + 1);
    }
    catch { }
    return n;
}

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

随便找个计算器,在十六进制模式下输入“7FFFFFFF”,然后切换到十进制。

2147483647.