Quote (moutonguerrier @ Nov 26 2021 01:20pm)
log_2 (1024) = 10
1 00 0000 0000
using log base 2 can make it faster
This.
Just remember that changing from a base A to a base B can be done using iterations of INT(log_A(x)) and exp_B(x) because a sum of n numbers in base A is EQUAL to the sum of the same numbers in base B
For example : transform 1030_10 in a number base 2 (X_2).
Step 1 ) INT(log2(1030)) = INT(10,something) = 10, exp_10(10) = 10 000 000 000, we have to transform the remaining part that is 1030 - exp_10(2) = 1030 - 1024 = 6
Step 2 ) INT(log2(6)) = INT(2,something) = 2, exp_10(2) = 100, remaining part is 6 - exp_2(2) = 6-4 = 2
Step 3 ) INT(log2(2)) = INT(1) = 1 (we will stop at step 3 because no more decimals to be transformed), exp_10(1) = 10
Summing steps will give that 1030_10 = 1024_10 + 4_10 + 2_10 = 10000000000_2 + 100_2 + 10_2 = 1 000 000 110
This is not the formal demonstration of course, the mathemathics behind it starts from the explanation given by @pelnied , I provided a different PoV because this is a programmer forum and the one I explained is pretty much one of the common algorithms to solve these problems.
This post was edited by NomadJe on Mar 26 2022 04:32am