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


当前回答

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

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

我更喜欢1 << 31 - 1

0x7fffffff因为你不需要计数fs

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

其他回答

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

214 -因为2.14近似于pi-1 48 = 6*8 64 = 8*8

横向写:

214_48_64_
and insert:
   ^  ^  ^
   7  3  7 - which is Boeing's airliner jet (thanks, sgorozco)

现在你得到了2147483647。

希望这能有所帮助。

如果你觉得以10为进制很难记住这个值,试试以2为进制: 1111111111111111111111111111111

“如果一个巨大的整数没有被回忆起,你就回忆这个助记符。”

现在数数每个单词中的字母。

在路径上使用Groovy:

groovy -e " println Integer.MAX_VALUE "

(在Java上下文中,Groovy对于快速参考非常有用。)