我总是记不住电话号码。我需要一个记忆规则。
当前回答
这就是我记住2147483647的方法
在遥远的大草原上,擎天柱三人对着四十个七分咒
2 - To
1 - A
4 - Far
7 - Savannah
4 - Quarter
8 - Optimus
3 - Trio
6 - Hexed
4 - Forty
7 - Septenary
其他回答
请记住,2^(10*x)大约是10^(3*x) -您可能已经习惯了千字节/千字节等。那就是:
2^10 = 1024 ~= one thousand
2^20 = 1024^2 = 1048576 ~= one million
2^30 = 1024^3 = 1073741824 ~= one billion
由于int型使用31位(符号为+ ~1位),所以只需将2^30乘以2就可以得到大约20亿。对于使用32位的unsigned int,再次翻倍为40亿。当然,误差系数越大,但你不需要记住准确的值(如果你需要,你应该使用一个预定义的常量)。这个近似值足够好,可以用来注意到什么时候某样东西可能会危险地接近溢出。
我能想到的最正确的答案是Int32.MaxValue。
在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)。
最简单的方法是查看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;
}
在路径上使用Groovy:
groovy -e " println Integer.MAX_VALUE "
(在Java上下文中,Groovy对于快速参考非常有用。)
推荐文章
- 在Android上将字符串转换为整数
- 将整数转换为字符串,以逗号表示千
- 在每个列表元素上调用int()函数?
- Java整数到字节数组
- 如何优雅地检查一个数字是否在一个范围内?
- 从整数列表中,求出最接近给定值的数
- 在python中将整数转换为二进制
- 如何将对象转换为int型
- Java如何处理整数下溢和溢出,如何检查它?
- 在Java和c#中,int和Integer的区别是什么?
- 是否有一种方法可以迭代一系列整数?
- 为什么整数除法产生一个浮点数而不是另一个整数?
- 在python中最安全的方法将浮点数转换为整数?
- 我如何工作围绕JavaScript的parseInt八进制行为?
- 将两个整数以唯一且确定的方式映射为一个整数