I have scenario where for any given number i need to identify the corresponding 2 to the power of value. for example if the given number is 12:
12 is represented in 2 to the power as: 2 to the power of 3 and 2 to the power of 2 5 is represented in 2 to the power as: 2 to the power of 2 and 2 to the power of 0
Can i know the algorithm named on this scenario
It's name is radix conversion. Convert your number to binary radix and you'll get your sum of power of 2
. For example,
12 = 1100
That means:
1 1 0 0
^ ^ ^ ^
| | | |
12 = 1 * (2^3) + 1* (2^2) + 0*(2^1) + 0*(2^0)
| | | |
V V V V
3 2 1 0
-it's by definition of what radix (numeral base) is.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments