我总是记不住电话号码。我需要一个记忆规则。
当前回答
我能想到的最正确的答案是Int32.MaxValue。
其他回答
大约是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
随便找个计算器,在十六进制模式下输入“7FFFFFFF”,然后切换到十进制。
2147483647.
2GB
(回答有最短长度限制吗?)
最简单的方法是查看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;
}
在Objective-C (iOS和OSX)中,只需要记住这些宏:
#define INT8_MAX 127
#define INT16_MAX 32767
#define INT32_MAX 2147483647
#define INT64_MAX 9223372036854775807LL
#define UINT8_MAX 255
#define UINT16_MAX 65535
#define UINT32_MAX 4294967295U
#define UINT64_MAX 18446744073709551615ULL
推荐文章
- 在Android上将字符串转换为整数
- 将整数转换为字符串,以逗号表示千
- 在每个列表元素上调用int()函数?
- Java整数到字节数组
- 如何优雅地检查一个数字是否在一个范围内?
- 从整数列表中,求出最接近给定值的数
- 在python中将整数转换为二进制
- 如何将对象转换为int型
- Java如何处理整数下溢和溢出,如何检查它?
- 在Java和c#中,int和Integer的区别是什么?
- 是否有一种方法可以迭代一系列整数?
- 为什么整数除法产生一个浮点数而不是另一个整数?
- 在python中最安全的方法将浮点数转换为整数?
- 我如何工作围绕JavaScript的parseInt八进制行为?
- 将两个整数以唯一且确定的方式映射为一个整数