-
October 4th, 2007, 06:24 AM
#1
A SIMPLE but Looks complicated integer addition
Dear Gurus,
Greetings....
i have a number to add in my math at 1st Std, the number is
123012301230123
+ 123012301230123
--------------------
2460246024602460
now i have to add this simple number using the computer. Can you tell me how do i accomplonish this...
PROBLEM : The thing is i have to read the size of a Disk which is in 11 tera bytes size... using the API GetDiskFreeSpaceEx()... And the value it gives exceeds atleast 14 digits what i belive. Question is how do i hold that value ? what size of integer i have to declare, i have used unsigned __int64 also but no use, any bigger size than this will be helpful.
Thank You,
Suren.
-
October 5th, 2007, 07:09 AM
#2
Re: A SIMPLE but Looks complicated integer addition
A solution is to store each number in an array of characters, and write a little function that will add the two numbers like you would do manually:
1. Take the two digits on the right side, add them, and store the result modulo 10 and the carry, if there is one.
2. Shift to the left.
3. Add the two digits and the carry if there is one, and store the result modulo 10 and the carry if there is one.
4. Start again step 2 until there is no more digit.
-
October 5th, 2007, 09:09 AM
#3
Re: A SIMPLE but Looks complicated integer addition
If you are using LARGE_INTEGER (required for calls to GetDiskFreeSpaceEx()) then the QuadPart member is a ULONGLOG (or unsigned __int64) and its maximum value is 18446744073709551615 which is much greater than the values you are using.
You can also use unsigned __int64 (or UINT64) if you prefer. Don't forget to use "%I64u" as a format specification when using printf-type functions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|