C++ int beyond 2,147,483,647?
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.
How do i attain it? do i need a certain library or piece of code to make it possible?
Cheers.
[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)..
[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)..
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
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.
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.
[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.
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
[/quote]
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!
[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.
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
[/quote]
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!
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".
[quote name='Bladelock' timestamp='1314783777' post='4855808']
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".
[/quote]
Yes, it was supposed to be long long.
will correct it now.
[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.
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!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement