- #1
martix
- 169
- 5
I'm trying to write a program that raises 2 to the specified power... and I need help.
And I don't mean an ordinary 2*2*2, n times and such.
The method used is slightly strange(kinda backwards).
For ex. take 256, what the program should do is
1. Take 2, check if the next digit is greater than 4. As it is there is an overflow which gets added to the product ot the first digit*2
2. Put the result in a string that is built piece by piece with concatenation.
3. Repeat for the next digit until the end. Then do the same for the next power, up to the desired one.
Issues I'm not sure of. Say you reach 512 - there is no zero digit to add the overflow of the first one. My guess is - artificially add one, right?
Then I have some questions - which will be faster?
1. Arrays or concatenation and substrings(a function which btw I did not find in the standart libraries).
2. This method or the usual mathematical ones.
And I don't mean an ordinary 2*2*2, n times and such.
The method used is slightly strange(kinda backwards).
For ex. take 256, what the program should do is
1. Take 2, check if the next digit is greater than 4. As it is there is an overflow which gets added to the product ot the first digit*2
2. Put the result in a string that is built piece by piece with concatenation.
3. Repeat for the next digit until the end. Then do the same for the next power, up to the desired one.
Issues I'm not sure of. Say you reach 512 - there is no zero digit to add the overflow of the first one. My guess is - artificially add one, right?
Then I have some questions - which will be faster?
1. Arrays or concatenation and substrings(a function which btw I did not find in the standart libraries).
2. This method or the usual mathematical ones.