1378

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

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Flinkman
  • 17,732
  • 8
  • 32
  • 53
  • 48
    unsigned: 2³²-1 = 4·1024³-1; signed: -2³¹ .. +2³¹-1, because the sign-bit is the highest bit. Just learn 2⁰=1 to 2¹⁰=1024 and combine. 1024=1k, 1024²=1M, 1024³=1G – comonad Mar 28 '11 at 20:01
  • 31
    I generally remember that every 3 bits is about a decimal digit. This gets me to the right order of magnitude: 32 bits is 10 digits. – Barmar Oct 02 '13 at 15:11
  • 8
    @JoachimSauer it can certainly help debugging if you learn to at least recognize these kinds of numbers. – Dunaril Nov 13 '13 at 16:38
  • 72
    "if a disk becomes full, deleting all mbytes will archive" (2 letters, 1 letter, 4 letters, 7 letters, 4 letters, 8 letters, 3 letters, 6 letters, 4 letters, 7 letters) – UltraCommit Mar 11 '14 at 14:30
  • 8
    A case, when the int32 is not enough: http://www.bbc.com/news/world-asia-30288542 – Balazs Nemeth Dec 04 '14 at 20:14
  • 1
    Why on earth do you want to remember the exact number? What @JoachimSauer said is the way you do away with the number. – Sнаđошƒаӽ Mar 21 '15 at 10:55
  • @UltraCommit why do you think your way is any more *useful* than plain 2,147,483,647? – Sнаđошƒаӽ Mar 21 '15 at 10:57
  • 5
    Again, "7 and seven 'f's" is an easy to remember mnemonic! (0x7fffffff) :) – ctpenrose May 07 '15 at 19:27
  • @Flinkman, file `limits.h` contains all that useful constants and much more. It would be more appropriate to ask about "where to find all that reference platform-specific values?". – Bulat M. Sep 14 '16 at 06:06
  • 1
    best way to remember it is not to try but just bookmark some internet page where the number is written on (i. e. this one) – BlueWizard Oct 13 '16 at 12:50
  • 2
    start with 2...7 days in a week, 2*7=14 that is 2147 now next two are 47+1=48, 214748, next is number of days in year - 1, 365-1=364 and end again with 7. You will now never be able to forget I guess :) 2 14 7 48 364 7 = 2 1 47 48 364 7 = 2147483647 –  Jan 19 '17 at 09:37
  • Slightly less than the view count of Gangnam Style on Youtube – kynnysmatto Apr 15 '17 at 12:36
  • 3
    this kind of question would be shamelessly trashed on today's SO. Especially anywhere near certain regions that shall not be named. – Chris May 12 '17 at 17:54
  • You can do `(1 << 31) -1` or `(1 << -1) -1` for signed 32-bit or `~0` for unsigned 32-bit. – Peter Lawrey Aug 30 '18 at 16:29
  • Just remember that it's the eighth Mersenne prime. That should help you remember the number. – Stephen Nov 01 '18 at 05:34
  • If you are 1337 h4x0r you will remember it with Piata: "Piata ate eg at" ... n00n? Let's say she ate that egg at noon. – G.Rassovsky Feb 11 '19 at 10:00
  • "If I have integer then possible max number isnt fifteen." Instead it's the concatenated lengths of those words. Cool stuff. – Rick Jun 18 '19 at 12:42
  • 8
    [This post is being discussed on meta](https://meta.stackoverflow.com/q/387214/6296561) – Zoe Jul 15 '19 at 13:36

45 Answers45

5062

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

Ben Hoffstein
  • 102,129
  • 8
  • 104
  • 120
  • 83
    My mnemonic: 2^10 is very near to 1000, so 2^(3*10) is 1000^3 or about 1 billion. One of the 32 bits is used for sign, so the max value is really only 2^31, which is about twice the amount you get for 2^(3*10): 2 billion. – 16807 Dec 03 '13 at 22:24
  • 1
    @16807 there's used zero bits for sign (on most architectures at least) if there was a bit used for sign there'd be to zeros and the absolut value of the min and max number would be the same but it's not. there's one more negative number than there's positive numbers because the representation is most widely used is two's complement – Rune FS Oct 08 '14 at 05:29
  • 1
    @RuneFS fair enough. What I mean to say is there's 32 bits but the extremes must be near 2^31. In any case, the mnemonic is only supposed to be accurate to the nearest billion. – 16807 Oct 08 '14 at 14:51
  • 164
    2147483647 without commas. – Vern D. Feb 05 '16 at 20:22
  • I did `2^32` and answer came out to be `4294967296`. I think the number you wrote is for signed max value(+ve)....I added `2,147,483,647 + 2,147,483,647` and the answer came out to be `4294967294`...Its 2 less than what I got with 2^32 any reasoning? @BenHoffstein – abhimanyuaryan Feb 07 '16 at 08:19
  • 3
    @AbhimanyuAryan Imagine it as a zero-based array and take the formula `2^index = value`. `2^0 = 1`, `2^1 = 2`, `2^2 = 4` ... `2^32 = 4294967296` wait ... you only have 32 bits, that is index 0-31. To get max value you actually have to calculate the sum of `2^n` with n from 0 to 31 or simpler `2^32 - 1` and you'll get '4294967295' as max for unsigned int, one less than anticipated. Now do the same with `2^31 - 1` for signed int and you'll get `2,147,483,647`. Do that two times (one for negative and one for positive int) and there you'll get your discrepancy of 2 from `2*(2^31 - 1)` to `2^32` ;) – Otto Abnormalverbraucher Feb 24 '16 at 16:12
  • 20
    Simply use: `Integer.MAX_VALUE` in Java. – Tim Apr 05 '16 at 13:31
  • 127
    2,147,483,647 = 0x7FFFFFFF, if you wanna remember it, just use hex. – roottraveller Aug 13 '16 at 06:18
  • 3
    simple formula (2 << 31) - 1 – xudifsd Jul 05 '17 at 01:50
  • 3
    @roottraveller At that point, you might as well just remember it in binary; 01111111111111111111111111111111 – pretzlstyle Jan 10 '18 at 20:59
  • @roottraveller 01111111111111111111111111111111 is octal in most languages, 0b01111111111111111111111111111111 would be the correct Java version – osundblad Nov 20 '18 at 20:59
  • Tue 19 Jan 2038 03:14:07 AM UTC is sure going to be fun – Josh Hibschman Jun 25 '19 at 17:28
  • Google =-2^31 for lower boundary and =2^31-1 for upper boundary. – Damith Jul 15 '19 at 03:31
493

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

Adrian Clark
  • 12,449
  • 5
  • 36
  • 42
  • 18
    Before this existed, I used to #define INT32_MIN and INT32_MAX in all my projects. – WildJoe Sep 12 '11 at 19:04
  • 3
    When you are programming: yes in 99% of cases. But you may want to know that it's something like ~ 2 billion to planning programming approaches or when working with data, although it's a very large number. :) – Andre Figueiredo Nov 17 '13 at 21:53
  • @sehe Isn't latin1/Windows 1252 obsolete by now? If it can't fit in the 7 bytes of ASCII, I don't think it deserves a place in main-memory. I mean... *all* UNICODE code-pages is kinda useful, but over a meg of skin-space seems a waste. (Not to mention it still doesn't include descriptive glyphs for "pageup/pagedown" or "pagehome/pageend") –  May 28 '14 at 14:18
  • try that in python2. Actually don't; I will tell you that the built in `int` object does not have this. :( – dylnmc Nov 20 '14 at 16:48
  • 1
    This property might be a good advice additionally to mentioning the correct number. However, I don't like this answer as it only mentions an unportable way of dertermining the value and it doesn't mention for which programming languages this is works, either... – mozzbozz Dec 12 '14 at 12:29
  • No offense, but can you print the value of `Int32.MaxValue` inside your head? ;-) The question asks for, though absurd, a way to remember the figure – Sнаđошƒаӽ Mar 21 '15 at 11:00
  • What language is this? I tried it in my Terminal (ShellScript), Python 3.6.4, and Python 2.7. It doesn't work in any of these! – aravk33 Mar 17 '18 at 08:47
  • @Cubetastic It is .Net Framework (any language really, but I normally code in C#). – Adrian Clark Mar 20 '18 at 03:57
  • That's not the maximum value. That's the name of a constant. – Mariano Dupont Feb 22 '19 at 21:08
439

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

Curd
  • 12,169
  • 3
  • 35
  • 49
315

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

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

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

Diamantatos Paraskevas
  • 3,874
  • 1
  • 20
  • 15
  • 30
    you know, when i started reading your answer i was expecting something practical, like the 20th digit. – JqueryToAddNumbers Nov 16 '15 at 09:55
  • 95
    This seems pretty cool. Do you have another memory rule to remember 1,867,996,680? I find it difficult to remember at which index to start looking.... – Alderath Jan 13 '16 at 08:35
  • 10
    "*if you can remember the entire Pi number...*" - no, you can't, it is [*irrational*](https://en.wikipedia.org/wiki/Irrational_number) {as are possibly one or two posts in this Q&As} 8-D – SlySven Jun 24 '16 at 21:45
  • Wow, this is actually pretty intense. – Krythic Aug 23 '16 at 00:42
  • 10
    @Alderath I typically remember it as the 10 decimals in sqrt(2) starting at digit number 380,630,713.... – htd Sep 06 '16 at 18:38
  • @SlySven Have to refer you Sнаđошƒаӽ's answer, where he recommends tattoos to aid memory. I love it. I don't think I'd mind seeing a tattoo with the value of pi on it :-) – WonderWorker Sep 13 '16 at 08:46
  • @Knickerless-Noggins maybe, but a numeric form would always be incomplete, though I suspect a geometric one would be relatively straightforward. Incidentally, according to [50 Interesting Facts About . . . Pi](http://facts.randomhistory.com/2009/07/03_pi.html) Fact 46: _Thirty-nine decimal places of pi suffice for computing the circumference of a circle girding the known universe with an error no greater than the radius of a hydrogen atom._ (apparently from: Pickover, Clifford A. ___Keys to Infinity___. Denver, CO: John Wiley & Sons, Inc.) So we don't need that many digits of π anyhow! – SlySven Sep 13 '16 at 23:56
  • 1
    Very cool stuff!! You can even search for it using an int type number as index since 1,867,996,680 < 2,147,483,647 ! – Rui Santos Nov 10 '16 at 11:51
  • 2
    @Alderath: The numeric string 1867996680 appears at the 380,630,713rd decimal digit of the Square Root of 2. – Yair Halberstadt Dec 14 '17 at 11:04
  • 1
    And 380630713 appears at the 779,302,404th decimal digit of Pi and at the 862,984,621st decimal digit of E. Take your pick! – Justsalt Aug 28 '18 at 20:35
  • 1
    @Justsalt: That sounds like a bug: it has messed up our loop variant, as now the index, which was going down so promisingly (2,147,483,647 > 1,867,996,680) has ballooned back up again: < 779,302,404. – PJTraill Dec 05 '18 at 12:31
291

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.

WildJoe
  • 5,740
  • 3
  • 26
  • 30
  • 13
    Speaking of remembering it as a phone number, it seems that there may be some phone spammers using it: http://mrnumber.com/1-214-748-3647 – Steven Oct 22 '10 at 14:57
  • 8
    "There is no "748" exchange in Dallas. This number is fake." - from the page linked by shambleh – Tarnay Kálmán Jan 21 '11 at 22:10
  • 104
    @Steven I don't think they're spammers, just people who accidentally stored the phone number as an `INT` instead of `VARCHAR` in MySQL. – Zarel Feb 09 '11 at 02:00
  • 8
    Tried calling it. It rang a few times then went to the error dial tone. =( – Krythic Feb 21 '16 at 03:52
172

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)
  • 4 years (48 months)
  • 3 years (36 months)
  • 4 years (48 months)

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

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!

Luke Bennett
  • 32,786
  • 3
  • 30
  • 57
  • 99
    That is one of the most complicated mneumonic devices I have seen. Impressive. – Ben Hoffstein Sep 18 '08 at 17:34
  • 9
    Heh, the likes of Derren Brown actually advocate this kind of approach - breaking a number down into something random but whieh is more memorable than just a load of numbers: http://www.channel4.com/entertainment/tv/microsites/M/mindcontrol/remember/memory.html – Luke Bennett Sep 18 '08 at 22:02
  • 19
    I have a better mnemonic: all you need to remember are 2 and 31, as it is apparently exactly 2^31 ! Oh, wait... – Tamas Czinege Jun 17 '09 at 10:08
  • Now that I actually have been typing this in, I keep thinking of your mnemonic... It's rather useful! – Shotgun Ninja Aug 11 '11 at 13:45
  • 28
    @DrJokepu I am not sure about the operator precedence... Does that mean `2^(31!)` or `(2^31)!`? – Alderath Mar 29 '12 at 10:27
  • Just note that you should not start this memory device from a [free ball situation](http://en.wikipedia.org/wiki/Maximum_break#Breaks_exceeding_147)... – sehe Feb 12 '13 at 09:31
  • The last two digits are 47, not 48. – Lucio May 19 '13 at 21:35
  • 1
    @Lucio Note that my answer relates in the first instance to the biggest negative number which ends in 48, not 47 – Luke Bennett May 21 '13 at 08:49
  • @LukeBennett according to http://www.belfasttelegraph.co.uk/news/alex-higgins/alex-higgins-a-155-break-impossible-not-for-higgy-28548775.html Higgins is said to be one of the few players in snooker history to have scored a break of 155 — rather remarkable as the 'maximum' is generally considered to be 147. But a 155 is possible, although it requires exceptional circumstances. – Diamantatos Paraskevas Jun 27 '17 at 09:16
144

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

Largest positive (32bit) value : 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
Tim
  • 41,901
  • 18
  • 127
  • 145
Aaren Cordova
  • 2,068
  • 1
  • 14
  • 7
75

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)

[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]

Maybe it would help you to remember.

Navin
  • 3,681
  • 3
  • 28
  • 52
Chizh
  • 1,019
  • 7
  • 16
61

That's how I remembered 2147483647:

  • 214 - because 2.14 is approximately pi-1
  • 48 = 6*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.

Hope this helps at least a bit.

  • 3
    Nice one! I think the 214 rule should be pi - 1. Also the mask shows 68 rather than 64. =) For aviation buffs like me, the 737 value should be easy to remember associating it with Boeing's medium-sized airliner jet. –  Sep 19 '13 at 19:51
  • You can go further than that. Drop the decimal and compare pi and 2^31-1. In the same positions you get 141 vs 147, so the last digit just becomes a 7. Then 592 vs 483, all are one digit off of each other. And 643 vs 647, it's that becoming a 7 thing again. – Peter Cooper Oct 10 '13 at 10:45
  • @PeterCooper Altho the decimals for pi starts with 1415926_5_35 (Note the 5, not a 4) – Moberg Feb 17 '14 at 22:27
  • 15
    My mnemonic is to take 4294967296 (which is easy to remember) and divide by 2 – M.M Sep 05 '14 at 05:39
55
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%).

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

Handy word-aligned capacity approximations:

  • 2^16 ~= 64 thousand // uint16
  • 2^32 ~= 4 billion // uint32, IPv4, unixtime
  • 2^64 ~= 16 quintillion (aka 16 billion billions or 16 million trillions) // uint64, "bigint"
  • 2^128 ~= 256 quintillion quintillion (aka 256 trillion trillion trillions) // IPv6, GUID
Wedge
  • 19,513
  • 7
  • 48
  • 71
46

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

2147483647.

darron
  • 4,284
  • 3
  • 36
  • 44
36

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

C

You can find it in C like that:

#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);
}

gives (well, without the ,)

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

You can get this with Java, too:

System.out.println(Integer.MAX_VALUE);

But keep in mind that Java integers are always signed.

Python 2

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

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

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

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • The Python answer is outdated see: https://stackoverflow.com/questions/13795758/what-is-sys-maxint-in-python-3 – NOhs Jun 10 '18 at 15:14
  • @NOhs I appreciate the link, but my Python answer is about "Python 2" (I add the 2 to the section title to make it more clear). So my answer is not outdated. (But Python 2, admittedly, is) – Martin Thoma Jun 10 '18 at 16:03
35

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

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.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
31

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

2^31 - 1 = 2147483647

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

EDIT for cantfindaname88

The count is 2^31 but the greatest can't be 2147483648 (2^31) because we count from 0, not 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

2^2 - 1 = 3

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

1: 100 ==> -4
2: 101 ==> -3
3: 110 ==> -2
4: 111 ==> -1
5: 000 ==>  0
6: 001 ==>  1
7: 010 ==>  2
8: 011 ==>  3
Community
  • 1
  • 1
Aerospace
  • 1,270
  • 12
  • 19
  • @cantfindaname88: 2^31 = total combinations, so it ranges from 0 to (2^31 -1). Yes the first is 0. – Luciano Aug 12 '15 at 12:37
30

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

The solution is 2,147,483,647

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

(Notice that there is one more negative value.)

Alex
  • 8,093
  • 6
  • 49
  • 79
Sarien
  • 6,647
  • 6
  • 35
  • 55
28

Well, aside from jokes, if you're really looking for a useful memory rule, there is one that I always use for remembering big numbers.

You need to break down your number into parts from 3-4 digits and remember them visually using projection on your cell phone keyboard. It's easier to show on a picture:

enter image description here

As you can see, from now on you just have to remember 3 shapes, 2 of them looks like a Tetris L and one looks like a tick. Which is definitely much easier than memorizing a 10-digit number.

When you need to recall the number just recall the shapes, imagine/look on a phone keyboard and project the shapes on it. Perhaps initially you'll have to look at the keyboard but after just a bit of practice, you'll remember that numbers are going from top-left to bottom-right so you will be able to simply imagine it in your head.

Just make sure you remember the direction of shapes and the number of digits in each shape (for instance, in 2147483647 example we have a 4-digit Tetris L and a 3-digit L).

You can use this technique to easily remember any important numbers (for instance, I remembered my 16-digit credit card number etc.).

Ivan Yurchenko
  • 3,762
  • 1
  • 21
  • 35
  • Neat idea! Shape 1 gives you 2147, Shape 2 gives you 483, and Shape 3 is supposed to give 647, but as drawn, it could be interpreted as 6**5**47. How do I know when to include all the crossed numbers (as in Shape 1) vs. when to skip some (as in Shape 3)? You also have to memorize that the shapes encode 4, 3, and 3 digits, respectively. Or you could draw Shape 3 with an arc from 6 to 4 instead of a straight line. – jskroch Oct 19 '17 at 16:17
  • @Squinch Well, particularly for remembering int.Max it shouldn't be a problem as you might know that it's about 2 billion so it has 10 numbers in it (and that means if the first shape has 4 numbers then the second and the third shapes have 3 accordingly). However, that's a nice point if you want to use this approach for any number. Also, there are numbers that are difficult to remember using this way (i.e. 1112 or something). On the other hand, it shouldn't be difficult to remember such number anyway. So I'd say it's up to you, let me know if you come up with something interesting for this. :) – Ivan Yurchenko Oct 19 '17 at 16:30
  • Yes, I was thinking about using this method to recall an arbitrary sequence of digits, but for this particular int.Max value, your method works fairly well. As you said, repeated digits are a problem. In fact, any repeated sequence (such as 2323) is a problem. Any sequence that crosses itself (such as 2058) is difficult to draw. Any memorization technique requires you to remember several pieces of information. It's personal preference what types of info best stick in your head. – jskroch Oct 19 '17 at 19:35
  • 1
    This is how I remember pin codes and similar, but then all of a sudden you need to type it in on your computer and realize that the numpad is vertically flipped. So that's a bit of a challenge. – nibarius May 22 '18 at 08:47
  • Somebody in [Dallas, Texas](https://www.worldatlas.com/na/us/tx/area-code-214.html), has received many strange phone calls and has no idea that you @IvanYurchenko are to blame. – Bob Stein Jun 06 '19 at 16:54
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:

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

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

Signed values, using 80 as the max signed value

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.

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.

0x7FFF + 0x0001 = 0x8000, so your loss is only one number, so using 0x7F... usually isn't a bad tradeoff for more reliable code, especially once you start using 32-bits or more

Joe Plante
  • 6,308
  • 2
  • 30
  • 23
21

First write out 47 twice, (you like Agent 47, right?), keeping spaces as shown (each dash is a slot for a single digit. First 2 slots, then 4)

--47----47

Think you have 12 in hand (because 12 = a dozen). Multiply it by 4, first digit of Agent 47's number, i.e. 47, and place the result to the right of first pair you already have

12 * 4 = 48
--4748--47 <-- after placing 48 to the right of first 47

Then multiply 12 by 3 (in order to make second digit of Agent 47's number, which is 7, you need 7 - 4 = 3) and put the result to the right of the first 2 pairs, the last pair-slot

12 * 3 = 36
--47483647 <-- after placing 36 to the right of first two pairs

Finally drag digits one by one from your hand starting from right-most digit (2 in this case) and place them in the first empty slot you get

2-47483647 <-- after placing 2
2147483647 <-- after placing 1

There you have it! For negative limit, you can think of that as 1 more in absolute value than the positive limit.

Practise a few times, and you will get the hang of it!

Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90
20

2GB

(is there a minimum length for answers?)

Rune
  • 815
  • 6
  • 17
15

If you happen to know your ASCII table off by heart and not MaxInt :
!GH6G = 21 47 48 36 47

Mark Hurd
  • 10,665
  • 10
  • 68
  • 101
15

The best rule to memorize it is:
21 (magic number!)
47 (just remember it)
48 (sequential!)
36 (21 + 15, both magics!)
47 again

Also it is easier to remember 5 pairs than 10 digits.

Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90
Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
15

Assuming .NET -

Console.WriteLine(Int32.MaxValue);
Kev
  • 118,037
  • 53
  • 300
  • 385
14

Interestingly, Int32.MaxValue has more characters than 2,147,486,647.

But then again, we do have code completion,

So I guess all we really have to memorize is Int3<period>M<enter>, which is only 6 characters to type in visual studio.

UPDATE For some reason I was downvoted. The only reason I can think of is that they didn't understand my first statement.

"Int32.MaxValue" takes at most 14 characters to type. 2,147,486,647 takes either 10 or 13 characters to type depending on if you put the commas in or not.

Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90
NotMe
  • 87,343
  • 27
  • 171
  • 245
  • 2
    But what counts is not how many characters you have to type, but how to memoize it. I'm sure `Iwannagohome` is easier to memoize than `298347829`. No reason for a -1, however. – glglgl Nov 25 '13 at 17:47
  • 3
    It could be less than that, just make your own max value snippet, "imv" perhaps? – BradleyDotNET Jan 22 '14 at 21:30
  • 4
    Characters `!=` Keystrokes. For this poor .Net user, it's `in`+`.`+`ma`+Return. – Michael Mar 13 '14 at 19:40
14

The easiest way to remember is to look at std::numeric_limits< int >::max()

For example (from 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;
}
Seq
  • 199
  • 1
  • 3
10

Just remember that 2^(10*x) is approximately 10^(3*x) - you're probably already used to this with kilobytes/kibibytes etc. That is:

2^10 = 1024                ~= one thousand
2^20 = 1024^2 = 1048576    ~= one million
2^30 = 1024^3 = 1073741824 ~= one billion

Since an int uses 31 bits (+ ~1 bit for the sign), just double 2^30 to get approximately 2 billion. For an unsigned int using 32 bits, double again for 4 billion. The error factor gets higher the larger you go of course, but you don't need the exact value memorised (If you need it, you should be using a pre-defined constant for it anyway). The approximate value is good enough for noticing when something might be a dangerously close to overflowing.

Brian
  • 116,865
  • 28
  • 107
  • 112
  • 10
    Offtopic: 2^4 = 4^2, therefore exponentiation is commutative! – Adam Liss Nov 05 '08 at 01:17
  • 10
    @Pier-OlivierThibault nope, I use it all the time! now I need to find out why all my math is coming out wrong. probably something to do with multiplication errors. anyway, bye! – tckmn May 11 '13 at 21:31
9

this is how i do it to remember 2,147,483,647

To a far savannah quarter optimus trio hexed forty septenary

2 - To
1 - A
4 - Far
7 - Savannah
4 - Quarter
8 - Optimus
3 - Trio
6 - Hexed
4 - Forty
7 - Septenary
Samuel
  • 9,883
  • 5
  • 45
  • 57
7

What do you mean? It should be easy enough to remember that it is 2^32. If you want a rule to memorize the value of that number, a handy rule of thumb is for converting between binary and decimal in general:

2^10 ~ 1000

which means 2^20 ~ 1,000,000

and 2^30 ~ 1,000,000,000

Double that (2^31) is rounghly 2 billion, and doubling that again (2^32) is 4 billion.

It's an easy way to get a rough estimate of any binary number. 10 zeroes in binary becomes 3 zeroes in decimal.

jalf
  • 243,077
  • 51
  • 345
  • 550
6

In Objective-C (iOS & OSX), just remember these macros:

#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
juniperi
  • 3,723
  • 1
  • 23
  • 30
5

Int32 means you have 32 bits available to store your number. The highest bit is the sign-bit, this indicates if the number is positive or negative. So you have 2^31 bits for positive and negative numbers.

With zero being a positive number you get the logical range of (mentioned before)

+2147483647 to -2147483648

If you think that is to small, use Int64:

+9223372036854775807 to -9223372036854775808

And why the hell you want to remember this number? To use in your code? You should always use Int32.MaxValue or Int32.MinValue in your code since these are static values (within the .net core) and thus faster in use than creating a new int with code.

My statement: if know this number by memory.. you're just showing off!

  • 2
    Most modern computers store numbers in "twos compliment" format. The highest (not lowest) bit is the sign. The neat thing with twos compement is that -ve numbers are handled by the natural overflow rules of the CPU. i.e 0xFF is 8 bit -1, add that to 0x01 (+1) and you get 0x100. Truncate bits above 8 to 0x00 and you have your answer. – Tom Leys Jun 17 '09 at 09:27
5

Remember this: 21 IQ ITEM 47

It can be de-encoded with any phone pad, or you can just write one down yourself on a paper.

In order to remember "21 IQ ITEM 47", I would go with "Hitman:Codename 47 had 21 missions, which were each IQ ITEM's by themselves".

Or "I clean teeth at 21:47 every day, because I have high IQ and don't like items in my mouth".

soprof
  • 326
  • 2
  • 6
4

Just remember that it's the eighth Mersenne prime.

If that's too hard, it's also the third of only four known double Mersenne primes.

Edit per comment request:

The Euclid-Euler theorem states that every even perfect number has the form 2^(n − 1) (2^n − 1), where 2^n − 1 is a prime number. The prime numbers of the form 2^n − 1 are known as Mersenne primes, and require n itself to be prime.

We know that the length of an INT32 is of course 32 bits. Given the generally accepted understanding of 2's complement, a signed INT32 is 32 bits - 1 bit.

To find the magnitude of a binary number with a given number of bits we generally raise 2 to the power n, minus 1, where n is equal to the number of bits.

Thus the magnitude calculation is 2^(32 - 1) - 1 = 2^31 - 1. 31 is prime and as outlined above, prime numbers of this form are Mersenne primes. We can prove it is the eight of such simply by counting them. For further details, please ask Euler, or maybe Bernoulli (to whom he wrote about them).

See: https://books.google.ie/books?id=x7p4tCPPuXoC&printsec=frontcover&dq=9780883853283&hl=en&sa=X&ved=0ahUKEwilzbORuJLdAhUOiaYKHcsZD-EQ6AEIKTAA#v=onepage&q=9780883853283&f=false

Toby
  • 9,696
  • 16
  • 68
  • 132
4

2147483647

Here's what you need to remember:

  • It's 2 billion.
  • The next three triplets are increasing like so: 100s, 400s, 600s
  • The first and the last triplet need 3 added to them so they get rounded up to 50 (eg 147 + 3 = 150 & 647 + 3 = 650)
  • The second triplet needs 3 subtracted from it to round it down to 80 (eg 483 - 3 = 480)

Hence 2, 147, 483, 647

G.Rassovsky
  • 774
  • 1
  • 10
  • 23
4

I made a couple genius methods in C# that you can take advantage of in your production environment:

public static int GetIntMaxValueGenius1()
{
    int n = 0;
    while (++n > 0) { }
    return --n;
}

public static int GetIntMaxValueGenius2()
{
    int n = 0;
    try
    {
        while (true)
            n = checked(n + 1);
    }
    catch { }
    return n;
}
yazanpro
  • 4,512
  • 6
  • 44
  • 66
  • 1
    I was thinking of some kind of method that would guess trillions of random integers, and return the highest one. – Slothario Jan 09 '19 at 21:55
4

With Groovy on the path:

groovy -e " println Integer.MAX_VALUE "

(Groovy is extremely useful for quick reference, within a Java context.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Michael Easter
  • 23,733
  • 7
  • 76
  • 107
2

To never forget the maximum value of any type:

If it has 32 bits, the largest possible value would be the 32 bits with the number 1:

enter image description here

The result would be 4294967295 in decimal:

enter image description here

But, as there is also the representation of negative numbers, divide 4294967295 by 2 and get 2147483647.

Therefore, a 32-bit integer is capable of representing -2147483647 to 2147483647

Guilherme Fidelis
  • 1,022
  • 11
  • 20
  • You can, you know, just get 2^31 (which is indeed also how it is stored in ram- one bit for positive/negative flag and 31 bits for the number), which will automatically be the half. And subtract one for the number zero (in your case you get 2147483647.5, not 2147483647 as you don't account for that). – ave May 06 '17 at 09:46
2

This is how I remember...
In hex, a digit represents four bits, so 4 * 8 = 32, so the max signed 32 bit int is:

0xFFFFFFFF >> 1 # => 2147483647
Sean Vikoren
  • 1,084
  • 1
  • 13
  • 24
  • This would probably work. I wish the guy that downvoted you would give you an explanation. – Joe Plante Aug 15 '13 at 17:41
  • 3
    @JoePlante The question asker was asking for a way that he, as a human, could memorize the number (as in, its decimal digits). I don't know about you, but parsing hexadecimal and then bit shifting isn't an intuitive operation on my mental hardware. If you're going to take this approach, you might as well just calculate 2^31-1. – Mark Amery Aug 27 '13 at 19:56
  • The question I was answering was "What is the maximum value for a int32?" I do see your point @MarkAmery, but remembering to type this line into an interpreter or into a print statement is actually how I remember the numbers. It also works as a general pattern for other sizes. Thank you for the support @JoePlante! – Sean Vikoren Aug 28 '13 at 22:57
  • No problem. After 16 bits, I simply stopped memorizing because you can always look it up. 0xFFFFFFFF >> 1 I feel is correct in a lot of cases because if you need to go to 64 bits, 0xFFFFFFFFFFFFFFFF >> 1 also works. 0xFFFF >> 1 and 0xFF >> 1 also works. I'm not sure if this works in languages with signed values or not, but still I feel it's viable – Joe Plante Sep 01 '13 at 14:20
1

You will find in binary the maximum value of an Int32 is 1111111111111111111111111111111 but in ten based you will find it is 2147483647 or 2^31-1 or Int32.MaxValue

trinalbadger587
  • 1,905
  • 1
  • 18
  • 36
1

Using Java 9's REPL, jshell:

$ jshell
|  Welcome to JShell -- Version 9-Debian

jshell> System.out.println(Integer.MAX_VALUE)
2147483647
Michael Easter
  • 23,733
  • 7
  • 76
  • 107
1

Try in Python:

>>> int('1' * 31, base=2)
2147483647
g10guang
  • 4,647
  • 3
  • 28
  • 22
1

It is very easy to remember. In hexadecimal one digit is 4 bits. So for unsigned int write 0x and 8 fs (0xffffffff) into a Python or Ruby shell to get the value in base 10. If you need the signed value, just remember that the highest bit is used as the sign. So you have to leave that out. You only need to remember that the number where the lower 3 bits are 1 and the 4th bit is 0 equals 7, so write 0x7fffffff into a Python or Ruby shell. You could also write 0x100000000 - 1 and 0x80000000 - 1, if that is more easy to you to remember.

panzi
  • 7,517
  • 5
  • 42
  • 54
0

In C use INT32_MAX after #include <stdint.h>. In C++ use INT32_MAX after #include <cstdint>.

Or INT_MAX for platform-specific size or UINT32_MAX or UINT_MAX for unsigned int. See http://www.cplusplus.com/reference/cstdint/ and http://www.cplusplus.com/reference/climits/.

Or sizeof(int).

Reed Hedges
  • 1,590
  • 2
  • 15
  • 17
0

In general you could do a simple operation which reflects the very nature of a Int32, fill all the available bits with 1's - That is something which you can hold easily in your memory. It works basically the same way in most languages, but i'm going with Python for the example:

max = 0
bits = [1] * 31 # Generate a "bit array" filled with 1's
for bit in bits:
    max = (max << 1) | bit
# max is now 2147483647

For unsigned Int32's, make it 32 instead of 31 1's.

But since there are posted a few more adventurous approaches, i began to think of formulas, just for the fun of it...

Formula 1 (Numbers are concatenated if no operator is given)

  • a = 4
  • b = 8
  • ba/a
  • ab-1
  • ab
  • ab-a-b
  • ab-1

Python quickcheck

a = 4
b = 8
ab = int('%d%d' % (a, b))
ba = int('%d%d' % (b, a))
'%d%d%d%d%d' % (ba/a, ab-1, ab, ab-a-b, ab-1)
# gives '2147483647'

Formula 2

  • x = 48
  • x/2-3
  • x-1
  • x
  • x*3/4
  • x-1

Python quickcheck

x = 48
'%d%d%d%d%d' % (x/2-3, x-1, x, x*3/4, x-1) 
# gives '2147483647'
wiesion
  • 2,349
  • 12
  • 21
0

"If a huge integer isn't recalled, you recall this mnemonic."

Now count the letters in each word.

Matt Malone
  • 361
  • 4
  • 25
-1
max_signed_32_bit_num = 1 << 31 - 1;  // alternatively ~(1 << 31)

A compiler should optimize it anyway.

I prefer 1 << 31 - 1 over

0x7fffffff because you don't need count fs

unsigned( pow( 2, 31 ) ) - 1 because you don't need <math.h>

lllllllllll
  • 144
  • 7
  • You can use underscores to improve the readability of some languages. Java and Swift support this from what I know, perhaps others. `0x7FFF_FFFF` – Alexander Mar 18 '17 at 17:18
-1

It's 231 − 1 (32 bits, one is used for sign).

If you want an approximate value, use 210 = 1024 ≈ 103, so 231 ≈ 2*109. If you want to compute an exact value by hand, use exponentiation by squaring to get to 232 = 2(25) and divide by two. You only need to square five times to get 232:

2*2 = 4
4*4 = 16
16*16 = 256
256*256 = 25*25*100 + 2*250*6 + 36 = 62500 + 3000 + 36 = 65536
65536*65536 =65000*65000 + 2*65000*536 + 536*536 =  
4225000000 + 130000*536 + (250000 + 3600 + 36*36) =
4225000000 + 69680000 + 250000 + 3600 + 1296 =
4294967296

dividing this by two and subtracting one gives you 2,147,483,647. If you don't need all digits, but only want say, the first three significant digits, the computations on each squaring step are very easy.

Michael
  • 8,362
  • 6
  • 61
  • 88
saolof
  • 1,097
  • 1
  • 15
  • 12