BigNum
-
Hi there guys! I wrote a BigNum class with two operations (addition and subtraction) and it consists of an array of integers. But lets suppose I read two numbers, with the following digit separation: 120 43 353 54 345 54 345 455 34 344 This is in base ten. Adding them together I get: 174 388 808 88 689 Which, obviously, is wrong. I used the standard addition algorithm, and it seems correct, so my question is: after "manipulating" the values, how can I print them correctly in base 10? Or do I need to keep a byte string with the digits and start from there? Best regards
Fratelli
-
Hi there guys! I wrote a BigNum class with two operations (addition and subtraction) and it consists of an array of integers. But lets suppose I read two numbers, with the following digit separation: 120 43 353 54 345 54 345 455 34 344 This is in base ten. Adding them together I get: 174 388 808 88 689 Which, obviously, is wrong. I used the standard addition algorithm, and it seems correct, so my question is: after "manipulating" the values, how can I print them correctly in base 10? Or do I need to keep a byte string with the digits and start from there? Best regards
Fratelli
How you will read big num & fill it in array of int?
AndreFratelli wrote:
I used the standard addition algorithm
Please past code over here.
Do not trust a computer... Always check what computer is doing regards, Divyang Mithaiwala Software Engineer
-
Hi there guys! I wrote a BigNum class with two operations (addition and subtraction) and it consists of an array of integers. But lets suppose I read two numbers, with the following digit separation: 120 43 353 54 345 54 345 455 34 344 This is in base ten. Adding them together I get: 174 388 808 88 689 Which, obviously, is wrong. I used the standard addition algorithm, and it seems correct, so my question is: after "manipulating" the values, how can I print them correctly in base 10? Or do I need to keep a byte string with the digits and start from there? Best regards
Fratelli
Your "digit separation" does not make sense to me. Looks like you forgot the carry (even though you say you used the standard addition algorithm) Converting to base 10 is easy, but not trivial (you can not convert every integer to base 10 and then concat them, I hope you didn't even think of that as a possibility)
-
Hi there guys! I wrote a BigNum class with two operations (addition and subtraction) and it consists of an array of integers. But lets suppose I read two numbers, with the following digit separation: 120 43 353 54 345 54 345 455 34 344 This is in base ten. Adding them together I get: 174 388 808 88 689 Which, obviously, is wrong. I used the standard addition algorithm, and it seems correct, so my question is: after "manipulating" the values, how can I print them correctly in base 10? Or do I need to keep a byte string with the digits and start from there? Best regards
Fratelli
AndreFratelli wrote:
...with the following digit separation: 120 43 353 54 345 54 345 455 34 344
Is it normal to have some groups of 2 and others of 3?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Hi there guys! I wrote a BigNum class with two operations (addition and subtraction) and it consists of an array of integers. But lets suppose I read two numbers, with the following digit separation: 120 43 353 54 345 54 345 455 34 344 This is in base ten. Adding them together I get: 174 388 808 88 689 Which, obviously, is wrong. I used the standard addition algorithm, and it seems correct, so my question is: after "manipulating" the values, how can I print them correctly in base 10? Or do I need to keep a byte string with the digits and start from there? Best regards
Fratelli
AndreFratelli wrote:
120 43 353 54 345 54 345 455 34 344
You digit separation doesn't make sense. Do your operations make sense, instead? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]