热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

一个int32的最大值是多少?-Whatisthemaximumvalueforanint32?

Icanneverrememberthenumber.Ineedamemoryrule.我永远记不住那个号码。我需要一个记忆规则。

I can never remember the number. I need a memory rule.

我永远记不住那个号码。我需要一个记忆规则。

46 个解决方案

#1


4501  

It's 2,147,483,647. Easiest way to memorize it is via a tattoo.

它是2147483647。最简单的记忆方法就是纹身。

#2


453  

The most correct answer I can think of is Int32.MaxValue.

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

#3


389  

If you think the value is too hard to remember in base 10, try base 2: 1111111111111111111111111111111

如果你觉得在基地10很难记住这个值,试试基地2:111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

#4


257  

It's 10 digits, so pretend it's a phone number (assuming you're in the US). 214-748-3647. I don't recommend calling it.

它是10位数字,所以假设它是一个电话号码(假设你在美国)。214-748-3647。我不推荐这样称呼它。

#5


191  

if you can remember the entire Pi number, then the number you are looking for is at the position 1,867,996,680 till 1,867,996,689 of the decimal digits of Pi

如果你能记住整个圆周率,那么你要找的是圆周率小数点后1,867,996,680到1,867,996,689的位置

The numeric string 2147483647 appears at the 1,867,996,680 decimal digit of Pi. 3.14......86181221809936452346214748364710527835665425671614...

数字字符串2147483647出现在圆周率的1,867,996,680位上。

source: http://www.subidiom.com/pi/

来源:http://www.subidiom.com/pi/

#6


151  

Rather than think of it as one big number, try breaking it down and looking for associated ideas eg:

与其把它想成一个大数字,不如试着把它分解并寻找相关的想法。

  • 2 maximum snooker breaks (a maximum break is 147)
  • 最大破纪录2次(最高破纪录为147次)
  • 4 years (48 months)
  • 4年(48个月)
  • 3 years (36 months)
  • 3年(36个月)
  • 4 years (48 months)
  • 4年(48个月)

The above applies to the biggest negative number; positive is that minus one.

以上适用于最大负数;正的是- 1。

Maybe the above breakdown will be no more memorable for you (it's hardly exciting is it!), but hopefully you can come up with some ideas that are!

也许以上的故障不会给你留下深刻的印象(这一点也不令人兴奋!),但希望你能想出一些点子!

#7


135  

Largest negative (32bit) value : -2147483648
(1 <<31)

最大负(32位)值:-2147483648 (1 <31)

Largest positive (32bit) value : 2147483647
~(1 <<31)

最大正(32位)值:2147483647 ~(1 <31)

Mnemonic: "drunk AKA horny"

助记:“醉又名角”

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

#8


63  

Anyway, take this regex (it determines if the string contains a non-negative Integer in decimal form that is also not greater than Int32.MaxValue)

无论如何,使用这个regex(它确定字符串是否包含不大于Int32.MaxValue的小数形式的非负整数)

[0-9]{1,9}|[0-1][0-9]{1,8}|20[0-9]{1,8}|21[0-3][0-9]{1,7}|214[0-6][0-9]{1,7}|2147[0-3][0-9]{1,6}|21474[0-7][0-9]{1,5}|214748[0-2][0-9]{1,4}|2147483[0-5][0-9]{1,3}|21474836[0-3][0-9]{1,2}|214748364[0-7]

[0 - 9]{ 1,9 } |(0 - 1)[0 - 9]{ 1,8 } | 20[0 - 9]{ 1,8 } | 21(0 - 3)[0 - 9]{ 1,7 } | 214年[-][0 - 9]{ 1,7 } | 2147(0 - 3)[0 - 9]{ 1,6 } | 21474(鹿)[0 - 9]{ 1,5 } | 214748年[0][0 - 9]{ 1 4 } | 2147483(0 - 5)[0 - 9]{ 1,3 } | 21474836(0 - 3)[0 - 9]{ 1,2 } | 214748364(鹿)

Maybe it would help you to remember.

也许这能帮你记住。

#9


58  

That's how I remembered 2147483647:

这就是我对2147483647的记忆:

  • 214 - because 2.14 is approximately pi-1
  • 因为2。14约等于-1
  • 48 = 6*8
  • 48 = 6 * 8
  • 64 = 8*8
  • 64 = 8 * 8

Write these horizontally:

写这些水平:

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

Now you've got 2147483647.

现在你有2147483647。

Hope this helps at least a bit.

希望这至少能有所帮助。

#10


53  

2^(x+y) = 2^x * 2^y

2^10 ~ 1,000
2^20 ~ 1,000,000
2^30 ~ 1,000,000,000
2^40 ~ 1,000,000,000,000
(etc.)

2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
2^7 = 128
2^8 = 256
2^9 = 512

So, 2^31 (signed int max) is 2^30 (about 1 billion) times 2^1 (2), or about 2 billion. And 2^32 is 2^30 * 2^2 or about 4 billion. This method of approximation is accurate enough even out to around 2^64 (where the error grows to about 15%).

2 ^ 31(int max)签署的是2 ^ 30(约10亿)* 2 ^ 1(2),或约20亿。和2 ^ 32是2 ^ 30 * 2 ^ 2约40亿。这种近似方法足够准确甚至2 ^ 64左右(误差增长约15%)。

If you need an exact answer then you should pull up a calculator.

如果你需要一个确切的答案,你应该用计算器。

Handy word-aligned capacity approximations:

方便的字之间对齐容量近似:

  • 2^16 ~= 64 thousand // uint16
  • 2 ^ 16 ~ = 6.4万/ / uint16
  • 2^32 ~= 4 billion // uint32, IPv4, unixtime
  • 2 ^ 32 ~ = 40亿/ / uint32 unixtime IPv4
  • 2^64 ~= 16 quintillion (aka 16 billion billions or 16 million trillions) // uint64, "bigint"
  • 2 ^ 64 ~ = 1600亿亿(即160亿数十亿美元或1600万万亿)/ / uint64,“长整型数字
  • 2^128 ~= 256 quintillion quintillion (aka 256 trillion trillion trillions) // IPv6, GUID
  • 2 ^ 128 ~ = 128(即256亿亿亿万亿)/ / IPv6,GUID

#11


43  

Just take any decent calculator and type in "7FFFFFFF" in hex mode, then switch to decimal.

只要使用任何像样的计算器,输入“7fffff”在十六进制模式,然后切换到十进制。

2147483647.

2147483647。

#12


31  

Here's a mnemonic for remembering 2**31, subtract one to get the maximum integer value.

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

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

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

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

I've used the powers of two up to 18 often enough to remember them, but even I haven't bothered memorizing 2**31. It's too easy to calculate as needed or use a constant, or estimate as 2G.

我经常用2到18的幂来记住它们,但即使是我也懒得记住2**31。它太容易按需要计算或使用常数,或估计为2G。

#13


31  

32 bits, one for the sign, 31 bits of information:

32位,1位符号,31位信息:

2^31 - 1 = 2147483647

Why -1?
Because the first is zero, so the greatest is the count minus one.

为什么1 ?因为第一个是0,所以最大的数是- 1。

EDIT for cantfindaname88

编辑对cantfindaname88

The count is 2^31 but the greatest can't be 2147483648 (2^31) because we count from 0, not 1.

数是2 ^ 31但最不能2147483648(2 ^ 31)因为我们计数从0,而不是1。

Rank   1 2 3 4 5 6 ... 2147483648
Number 0 1 2 3 4 5 ... 2147483647

Another explanation with only 3 bits : 1 for the sign, 2 for the information

另一种解释只有3位:1表示符号,2表示信息。

2^2 - 1 = 3

Below all the possible values with 3 bits: (2^3 = 8 values)

与3位:下面的所有可能的值(2 ^ 3 = 8值)

1: 100 ==> -4
2: 101 ==> -3
3: 110 ==> -2
4: 111 ==> -1
5: 000 ==>  0
6: 001 ==>  1
7: 010 ==>  2
8: 011 ==>  3

#14


28  

Well, it has 32 bits and hence can store 2^32 different values. Half of those are negative.

嗯,它有32位,因此可以存储2 ^ 32个不同的值。其中一半是负数。

The solution is 2,147,483,647

解决方案是2147483647

And the lowest is −2,147,483,648.

和最低是2147483648−。

(Notice that there is one more negative value.)

(注意还有一个负值)

#15


27  

It's about 2.1 * 10^9. No need to know the exact 2^{31} - 1 = 2,147,483,647.

是2.1 * 10 ^ 9。不需要知道确切的2 ^ 31 } { - 1 = 2147483647。

C

You can find it in C like that:

你可以在C中找到

#include 
#include 

main() {
    printf("max int:\t\t%i\n", INT_MAX);
    printf("max unsigned int:\t%u\n", UINT_MAX);
}

gives (well, without the ,)

给予(没有,)

max int:          2,147,483,647
max unsigned int: 4,294,967,295
C++ 11
std::cout <::max() <<"\n";
std::cout <::max() <<"\n";
Java

You can get this with Java, too:

Java也可以这样做:

System.out.println(Integer.MAX_VALUE);

But keep in mind that Java integers are always signed.

但是请记住,Java整数总是有符号的。

Python

Python has arbitrary precision integers. But in Python 2, they are mapped to C integers. So you can do this:

Python具有任意的精度整数。但是在Python 2中,它们被映射成C整数。你可以这样做:

import sys
sys.maxint
>>> 2147483647
sys.maxint + 1
>>> 2147483648L

So Python switches to long when the integer gets bigger than 2^31 -1

所以Python开关长当整数大于2 ^ 31 - 1

#16


25  

At this point, I'd say the easiest mnemonic is to type "stackoverflow.com" TAB "maximum int32" into Chrome.

在这一点上,我认为最简单的助记符是将“stackoverflow.com”选项卡“maximum int32”输入到Chrome中。

There is a recursion --> stack overflow joke in there somewhere. I'm just not that geeky.

这里有一个递归——>栈溢出笑话。我只是没那么怪。

#17


21  

The easiest way to do this for integers is to use hexadecimal, provided that there isn't something like Int.maxInt(). The reason is this:

对于整数,最简单的方法是使用十六进制,前提是不存在Int.maxInt()之类的东西。原因是这样的:

Max unsigned values

马克斯无符号值

8-bit 0xFF
16-bit 0xFFFF
32-bit 0xFFFFFFFF
64-bit 0xFFFFFFFFFFFFFFFF
128-bit 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Signed values, using 7F as the max signed value

有符号值,使用7F作为最大有符号值

8-bit 0x7F
16-bit 0x7FFF
32-bit 0x7FFFFFFF
64-bit 0x7FFFFFFFFFFFFFFF

Signed values, using 80 as the max signed value

有符号值,使用80作为最大有符号值

8-bit 0x80
16-bit 0x8000
32-bit 0x80000000
64-bit 0x8000000000000000

How does this work? This is very similar to the binary tactic, and each hex digit is exactly 4 bits. Also, a lot of compilers support hex a lot better than they support binary.

这是如何工作的呢?这与二进制策略非常相似,每个十六进制数字恰好是4位。此外,许多编译器支持十六进制比支持二进制要好得多。

F hex to binary: 1111
8 hex to binary: 1000
7 hex to binary: 0111
0 hex to binary: 0000

So 7F is equal to 01111111 / 7FFF is equal to 0111111111111111. Also, if you are using this for "insanely-high constant", 7F... is safe hex, but it's easy enough to try out 7F and 80 and just print them to your screen to see which one it is.

所以7F等于01111111 / 7FFF等于0111111111111111。另外,如果你用这个来表示“高得离谱的常数”,7F…是安全的十六进制,但是很容易尝试7F和80,然后把它们打印到你的屏幕上看看是哪一个。

0x7FFF + 0x0001 = 0x8000, so your loss is only one number, so using 0x7F... usually isn't a bad tradeoff for more reliable cod

推荐阅读
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • vue使用
    关键词: ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • Linux环境变量函数getenv、putenv、setenv和unsetenv详解
    本文详细解释了Linux中的环境变量函数getenv、putenv、setenv和unsetenv的用法和功能。通过使用这些函数,可以获取、设置和删除环境变量的值。同时给出了相应的函数原型、参数说明和返回值。通过示例代码演示了如何使用getenv函数获取环境变量的值,并打印出来。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • 本文讨论了clone的fork与pthread_create创建线程的不同之处。进程是一个指令执行流及其执行环境,其执行环境是一个系统资源的集合。在调用系统调用fork创建一个进程时,子进程只是完全复制父进程的资源,这样得到的子进程独立于父进程,具有良好的并发性。但是二者之间的通讯需要通过专门的通讯机制,另外通过fork创建子进程系统开销很大。因此,在某些情况下,使用clone或pthread_create创建线程可能更加高效。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文介绍了Python语言程序设计中文件和数据格式化的操作,包括使用np.savetext保存文本文件,对文本文件和二进制文件进行统一的操作步骤,以及使用Numpy模块进行数据可视化编程的指南。同时还提供了一些关于Python的测试题。 ... [详细]
  • 本文介绍了利用ARMA模型对平稳非白噪声序列进行建模的步骤及代码实现。首先对观察值序列进行样本自相关系数和样本偏自相关系数的计算,然后根据这些系数的性质选择适当的ARMA模型进行拟合,并估计模型中的位置参数。接着进行模型的有效性检验,如果不通过则重新选择模型再拟合,如果通过则进行模型优化。最后利用拟合模型预测序列的未来走势。文章还介绍了绘制时序图、平稳性检验、白噪声检验、确定ARMA阶数和预测未来走势的代码实现。 ... [详细]
author-avatar
--郑煦桥--
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有