C++/CLI Convert long Strings to Int
-
int BigNumber = Convert::ToInt64(BigString);
I am trying to create an Int (BigNumber) from a very long String (BigString, which is made up of let's say ~25 characters). Should I use ToInt64 or ToInt32? What are the character limits of the two? What's better? Thank you!
-
int BigNumber = Convert::ToInt64(BigString);
I am trying to create an Int (BigNumber) from a very long String (BigString, which is made up of let's say ~25 characters). Should I use ToInt64 or ToInt32? What are the character limits of the two? What's better? Thank you!
Hi, you probably know what the largest value is a 32-bit int can hold; if not look at Int32.MaxValue. a 64-bit int can hold about the square of that. Neither will reach a 25-digit string representation assuming decimal and no leading zeroes. Also it does not make sense to call ToInt64 and store the result in an int; the compiler will object to that. :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
-
int BigNumber = Convert::ToInt64(BigString);
I am trying to create an Int (BigNumber) from a very long String (BigString, which is made up of let's say ~25 characters). Should I use ToInt64 or ToInt32? What are the character limits of the two? What's better? Thank you!
Neither Int32 or Int64 are going to hold a ~25 digit number. 2^32 = 4294967296 2^64 = 18446744073709551616
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Neither Int32 or Int64 are going to hold a ~25 digit number. 2^32 = 4294967296 2^64 = 18446744073709551616
Mark Salsbery Microsoft MVP - Visual C++ :java:
Mark Salsbery wrote:
2^32 = 4294967296 2^64 = 18446744073709551616
Actually for signed integers the maximum values are one less than half of those numbers. BTW: you should use thousand separator characters to keep such numbers somewhat readable... :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
-
Mark Salsbery wrote:
2^32 = 4294967296 2^64 = 18446744073709551616
Actually for signed integers the maximum values are one less than half of those numbers. BTW: you should use thousand separator characters to keep such numbers somewhat readable... :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
Yeah.....um....thanks for the tips Luc :rolleyes: ;P
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Yeah.....um....thanks for the tips Luc :rolleyes: ;P
Mark Salsbery Microsoft MVP - Visual C++ :java:
You err are welcome. :-D
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
-
Yeah.....um....thanks for the tips Luc :rolleyes: ;P
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Mark Salsbery wrote:
thanks for the tips
Here's another: If you give a man a fish he'll stink up the whole village, but give him a fishing rod, see where I'm going with this? Give him a fishing rod and he'll poke yer eye out.
:laugh: :jig:
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Mark Salsbery wrote:
thanks for the tips
Here's another: If you give a man a fish he'll stink up the whole village, but give him a fishing rod, see where I'm going with this? Give him a fishing rod and he'll poke yer eye out.
One should always wear safety glasses when using hazardous equipment, such as Windows PCs. :laugh: :laugh:
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets