Jump to content

  • Log In with Google      Sign In   
  • Create Account

C++ int beyond 2,147,483,647?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 Bladelock   Members   -  Reputation: 123

Like
0Likes
Like

Posted 31 August 2011 - 01:52 AM

Hi, out of curiousity, is it possible for a C++ integer (or long integer according to what i read) to go beyond 2,147,483,647?

How do i attain it? do i need a certain library or piece of code to make it possible?

Cheers.

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 31851

Like
1Likes
Like

Posted 31 August 2011 - 01:54 AM


What you're looking at there is 2^31
-1.


You can also use unsigned int (2^32-1), or long long (2^63-1), or unsigned long long (2^64-1), or double (+inf)..

#3 ryan20fun   Members   -  Reputation: 1101

Like
3Likes
Like

Posted 31 August 2011 - 01:57 AM

Hi, out of curiousity, is it possible for a C++ integer (or long integer according to what i read) to go beyond 2,147,483,647?

How do i attain it? do i need a certain library or piece of code to make it possible?

Cheers.

yes "long long" / "__int64" although the latter is compiler/OS/vendor specifiec as far as i know
they go from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
and uses 8 bytes.
big enough for you ?
check out this
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

#4 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 31 August 2011 - 02:38 AM

You can string a lot of ints to make a larger unit.

unsigned int tens = 0x00000000;
unsigned int ones = 0xFFFFFFFF;
ones++;
boolean overflowed = true;
if (ones == 0 && overflowed == true) {
tens ++;
ones = 0x00000000;
}
else
{
overflowed = false;
}

Just mentioning that ints can do this.

#5 Shintah   Members   -  Reputation: 109

Like
2Likes
Like

Posted 31 August 2011 - 02:43 AM

If you want arbitrarily big numbers you can use a library like https://mattmccutchen.net/bigint/

#6 Bladelock   Members   -  Reputation: 123

Like
0Likes
Like

Posted 31 August 2011 - 03:02 AM


Hi, out of curiousity, is it possible for a C++ integer (or long integer according to what i read) to go beyond 2,147,483,647?

How do i attain it? do i need a certain library or piece of code to make it possible?

Cheers.

yes "log long" / "__int64" although the latter is compiler/OS/vendor specifiec as far as i know
they go from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
and uses 8 bytes.
big enough for you ?
check out this


awesome. did the trick. Thanks!
btw, is "log long" supposed to be "long long"? thought we were gonna use logarithms hehe.



If you want arbitrarily big numbers you can use a library like https://mattmccutchen.net/bigint/


Interesting. Will check this out. Thanks!




#7 Bladelock   Members   -  Reputation: 123

Like
0Likes
Like

Posted 31 August 2011 - 03:42 AM


Hi, out of curiousity, is it possible for a C++ integer (or long integer according to what i read) to go beyond 2,147,483,647?

How do i attain it? do i need a certain library or piece of code to make it possible?

Cheers.

yes "log long" / "__int64" although the latter is compiler/OS/vendor specifiec as far as i know
they go from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
and uses 8 bytes.
big enough for you ?
check out this


awesome. did the trick. Thanks!
btw, is "log long" supposed to be "long long"? thought we were gonna use logarithms hehe.



If you want arbitrarily big numbers you can use a library like https://mattmccutchen.net/bigint/


Interesting. Will check this out. Thanks!




#8 Brother Bob   Moderators   -  Reputation: 8606

Like
1Likes
Like

Posted 31 August 2011 - 05:26 AM

btw, is "log long" supposed to be "long long"? thought we were gonna use logarithms hehe.

Yes, it was most likely just a typo on his part; it's supposed to be "long long".

#9 ryan20fun   Members   -  Reputation: 1101

Like
1Likes
Like

Posted 31 August 2011 - 05:49 AM


btw, is "log long" supposed to be "long long"? thought we were gonna use logarithms hehe.

Yes, it was most likely just a typo on his part; it's supposed to be "long long".


Yes, it was supposed to be long long.
will correct it now.
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

#10 Bladelock   Members   -  Reputation: 123

Like
0Likes
Like

Posted 01 September 2011 - 06:13 AM



btw, is "log long" supposed to be "long long"? thought we were gonna use logarithms hehe.

Yes, it was most likely just a typo on his part; it's supposed to be "long long".


Yes, it was supposed to be long long.
will correct it now.


Awesome. Kudos to you!

#11 ChurchSkiz   Members   -  Reputation: 458

Like
0Likes
Like

Posted 01 September 2011 - 10:04 AM

You can also used unsigned long long if you need double the space. I think that trick let me do a project euler exercise without having to use the bigint library.

#12 yckx   Prime Members   -  Reputation: 1291

Like
0Likes
Like

Posted 01 September 2011 - 06:09 PM

You can also used unsigned long long if you need double the space. I think that trick let me do a project euler exercise without having to use the bigint library.

It's not really double the space; rather, the range starts at 0 instead of being centered on 0. But the size of the range remains unchanged.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS