I am writing a program that converts a hexadecimal number to a decimal number (without using the std::hex and std::dec stuff), and at one point need to change from a double to an int.. However when large numbers, such as 5,726,623,060.00000 are entered, they all get changed to -2,147,483,648 after being run through static_cast<int>... Any help as to how to get them to be converted correctly to (i.e 5,726,623,060.00000 to 5,726,623,060) would be very much appreciated!! Thanks!! :)
tofugamer
0
Newbie Poster
Recommended Answers
Jump to PostYes, use an int array as an accumulator:
0xFFFF = 15+240+ ... = [_|_|_|...|_|1|5]+[_|_|_|...|2|4|0] + ... = [_|_|_|...|2|5|5] + ...
Summing each new calculation into your array (you don't need more than one, just make sure you have things lined up and do the carries properly. This …
All 4 Replies
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
tofugamer
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
tofugamer
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.