我总是记不住电话号码。我需要一个记忆规则。
当前回答
如果你碰巧记住了你的ASCII表而不是MaxInt: gh6g = 21 47 48 36 47
其他回答
最简单的方法是查看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;
}
试试用Python:
>>> int('1' * 31, base=2)
2147483647
大约是2.1 * 10^9。不需要知道确切的2^{31}- 1 = 2,147,483,647。
C
你可以在C语言中找到它:
#include <stdio.h>
#include <limits.h>
main() {
printf("max int:\t\t%i\n", INT_MAX);
printf("max unsigned int:\t%u\n", UINT_MAX);
}
给出(好吧,没有,)
max int: 2,147,483,647
max unsigned int: 4,294,967,295
C + 11 +
std::cout << std::numeric_limits<int>::max() << "\n";
std::cout << std::numeric_limits<unsigned int>::max() << "\n";
Java
你也可以用Java得到这个:
System.out.println(Integer.MAX_VALUE);
但是请记住,Java整数总是有符号的。
Python 2
Python有任意的精确整数。但在python2中,它们被映射为C整数。所以你可以这样做:
import sys
sys.maxint
>>> 2147483647
sys.maxint + 1
>>> 2147483648L
所以当整数大于2^31 -1时,Python会切换为long
在路径上使用Groovy:
groovy -e " println Integer.MAX_VALUE "
(在Java上下文中,Groovy对于快速参考非常有用。)
这就是我如何记住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。
希望这能有所帮助。
推荐文章
- 在Android上将字符串转换为整数
- 将整数转换为字符串,以逗号表示千
- 在每个列表元素上调用int()函数?
- Java整数到字节数组
- 如何优雅地检查一个数字是否在一个范围内?
- 从整数列表中,求出最接近给定值的数
- 在python中将整数转换为二进制
- 如何将对象转换为int型
- Java如何处理整数下溢和溢出,如何检查它?
- 在Java和c#中,int和Integer的区别是什么?
- 是否有一种方法可以迭代一系列整数?
- 为什么整数除法产生一个浮点数而不是另一个整数?
- 在python中最安全的方法将浮点数转换为整数?
- 我如何工作围绕JavaScript的parseInt八进制行为?
- 将两个整数以唯一且确定的方式映射为一个整数