• Advertisement
Sign in to follow this  

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

This topic is 2332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
[font="Lucida Console"]
[font="Lucida Console"][font="arial, verdana, tahoma, sans-serif"]What you're looking at there is 2[sup]^31[/sup][/font][/font][/font][font="Lucida Console"][font="arial, verdana, tahoma, sans-serif"]-1.[/font][/font]


[font="Lucida Console"][font="arial, verdana, tahoma, sans-serif"]You can also use [/font][/font][font="Lucida Console"]unsigned int[/font] ([font="Lucida Console"][font="arial, verdana, tahoma, sans-serif"]2[sup]^32[/sup][/font][/font][font="arial, verdana, tahoma, sans-serif"]-1[/font]), or [font="Lucida Console"]long long[/font] ([font="Lucida Console"][font="arial, verdana, tahoma, sans-serif"]2[sup]^63[/sup][/font][/font][font="arial, verdana, tahoma, sans-serif"]-1[/font]), or [font="Lucida Console"]unsigned long long[/font] ([font="Lucida Console"][font="arial, verdana, tahoma, sans-serif"]2[sup]^64[/sup][/font][/font][font="arial, verdana, tahoma, sans-serif"]-1[/font]), or [font="Lucida Console"]double[/font] (+inf)..

Share this post


Link to post
Share on other sites
[quote name='Bladelock' timestamp='1314777136' post='4855785']
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.
[/quote]
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 [url="http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.80%29.aspx"]this[/url]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
If you want arbitrarily big numbers you can use a library like [url="https://mattmccutchen.net/bigint/"]https://mattmccutchen.net/bigint/[/url]

Share this post


Link to post
Share on other sites
[quote name='ryan20fun' timestamp='1314777474' post='4855788']
[quote name='Bladelock' timestamp='1314777136' post='4855785']
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.
[/quote]
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 [url="http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.80%29.aspx"]this[/url]
[/quote]

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



[quote name='Shintah' timestamp='1314780214' post='4855797']
If you want arbitrarily big numbers you can use a library like [url="https://mattmccutchen.net/bigint/"]https://mattmccutchen.net/bigint/[/url]
[/quote]

Interesting. Will check this out. Thanks!


Share this post


Link to post
Share on other sites
[quote name='ryan20fun' timestamp='1314777474' post='4855788']
[quote name='Bladelock' timestamp='1314777136' post='4855785']
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.
[/quote]
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 [url="http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.80%29.aspx"]this[/url]
[/quote]

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



[quote name='Shintah' timestamp='1314780214' post='4855797']
If you want arbitrarily big numbers you can use a library like [url="https://mattmccutchen.net/bigint/"]https://mattmccutchen.net/bigint/[/url]
[/quote]

Interesting. Will check this out. Thanks!


Share this post


Link to post
Share on other sites
[quote name='Bladelock' timestamp='1314783777' post='4855808']
btw, is "log long" supposed to be "long long"? thought we were gonna use logarithms hehe.
[/quote]
Yes, it was most likely just a typo on his part; it's supposed to be "long long".

Share this post


Link to post
Share on other sites
[quote name='Brother Bob' timestamp='1314790019' post='4855825']
[quote name='Bladelock' timestamp='1314783777' post='4855808']
btw, is "log long" supposed to be "long long"? thought we were gonna use logarithms hehe.
[/quote]
Yes, it was most likely just a typo on his part; it's supposed to be "long long".
[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='ryan20fun' timestamp='1314791388' post='4855830']
[quote name='Brother Bob' timestamp='1314790019' post='4855825']
[quote name='Bladelock' timestamp='1314783777' post='4855808']
btw, is "log long" supposed to be "long long"? thought we were gonna use logarithms hehe.
[/quote]
Yes, it was most likely just a typo on his part; it's supposed to be "long long".
[/quote]

Yes, it was supposed to be long long.
will correct it now.
[/quote]

Awesome. Kudos to you!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='ChurchSkiz' timestamp='1314893051' post='4856347']
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.
[/quote]
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement