tags:

views:

22192

answers:

22

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

+5  A: 

Well it has 32Bits and hence can store 2^32 different values. Half of those are negative. Do the maths.

That's a simple memory rule if you have a good calculator. :)

The solution btw is: +2,147,483,647

and the lowest ist −2,147,483,648

(notice that there is one more negative)

Corporal Touchy
It has 32 bits and hence can store 2^32 values. No less.
JB
You're of course right ;) I'll edit that.
Corporal Touchy
+98  A: 

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

Ben Hoffstein
hehe.. thanks. I will tattoo that 2,147,438,647.
Flinkman
i like the tattoo idear
Markus Lausberg
My way "It is more than two thousand million"
Tom Leys
+1 for being funny :)
Chalkey
You may want to tattoo `+/- 2147483647`...just in case you forget the negative value too. :-p
David Murdoch
+3  A: 

Assuming .NET -

Console.WriteLine(Int32.MaxValue);
Kev
+38  A: 

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

Aydsman
Damn, I was going to say that :-)
Ian Nelson
They made that property just for us slothful coders.
Camilo Martin
+20  A: 

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
That's my phone number you insensitive clod!
Ben Hoffstein
I wish that was my phone number.
Troy Howard
It's a Walmart in Dallas
Michael Hedgpeth
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
shambleh
+3  A: 

The value works out to 2,147,483,647.

That's (2^32-1)/2 because Int32 has 32 bits and half of it's values are negative.

Or, if you live in the world of .NET, don't bother remembering the number, just use Int32.MaxValue.

Kevin Berridge
2^32-1 is odd, so (2^32 - 1)/2 isn't an int. I think you mean (2^32)/2 - 1.
Adam Liss
It is indeed both an int and the correct int, since the extra will be truncated.
DeadMG
+13  A: 

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
That is one of the most complicated mneumonic devices I have seen. Impressive.
Ben Hoffstein
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
I have a better mnemonic: all you need to remember are 2 and 31, as it is apparently exactly 2^31 ! Oh, wait...
DrJokepu
+5  A: 

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

2147483647.

darron
Any decent calculator can do 2^31 as well.
Christoffer
+8  A: 
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
+1 handy approximation
Tom Leys
That's what the hard-drive makers said.
Scott Stafford
+3  A: 

2GB

(is there a minimum length for answers?)

Rune
Shouldn't that be GiB?
Jouke van der Maas
+3  A: 

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
Offtopic: 2^4 = 4^2, therefore exponentiation is commutative!
Adam Liss
+2  A: 

with Groovy on the path:

groovy -e " println Integer.MAX_VALUE "

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

Michael Easter
A: 

Int32.MaxValue

A: 

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
but it's not 2^32 - it's (2^31)-1
Steve Folly
+1  A: 

c++ : std::numeric_limits< int >::max()

Seq
+1  A: 

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!

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
You're right, the term last was incorrect. ;)
A: 

Anyway, take this regex (it determines if string contains not negative Integer in decimal form that 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]{1,1}"

Maybe it would help you to remember

Chizh
<sarcasm>Yes, that should make it MUCH easier to remember.</sarcasm>
Dubs
A: 

join this cool facebook group. notice that it is an unsigned int. that's why divide by two and subtract one. very easy to remember.

Roflcoptr
A: 

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.

Chris Lively
A: 

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

Curd
+1  A: 

Google "max value of int", the answer comes up in 0.39 seconds.

RobertC