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


当前回答

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

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

我更喜欢1 << 31 - 1

0x7fffffff因为你不需要计数fs

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

其他回答

这里有一个记忆2**31,减去1得到最大整数值的助记符。

a = 1, b = 2, c = 3 d = 4 = 5, f = 6 g = 7, 8 h = = 9

Boys And Dogs Go Duck Hunting, Come Friday Ducks Hide
2    1   4    7  4    8        3    6      4     8

我经常使用2到18的幂来记住它们,但即使是我也没有费心去记住2**31。根据需要计算或使用常数,或估计为2G太容易了。

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

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

我更喜欢1 << 31 - 1

0x7fffffff因为你不需要计数fs

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

有趣的是,Int32。MaxValue拥有超过2,147,486,647个字符。

但话说回来,我们有代码完成,

所以我想我们真正需要记住的是Int3<period>M<enter>,这在visual studio中只有6个字符。

更新 出于某种原因,我被否决了。我能想到的唯一原因是他们没有理解我的第一句话。

“Int32。MaxValue最多需要14个字符来输入。 2147,486,647需要输入10或13个字符,这取决于是否使用逗号。

在C语言中,在#include <stdint.h>后使用INT32_MAX。 在c++中,在#include <cstdint>后使用INT32_MAX。

或INT_MAX平台特定的大小或UINT32_MAX或UINT_MAX unsigned int。参见http://www.cplusplus.com/reference/cstdint/和http://www.cplusplus.com/reference/climits/。

或运算符(int)。

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