The text file contains integers. Replace all the numbers representing the number two in the integer degree by the combination 2 ^ n (where n is the power). For example: 8 - 2 ^ 3, 32 - 2 ^ 5
Tell me the algorithm for solving such problems.
Take a number, check, and not 2 if it is to the power of n , if yes - replace ...
Well, it’s very easy to check whether x degree 2 - to calculate x&(x-1) - for degree 2 it will be zero ... (although you still have to check that x itself is not zero).
The degree to calculate the special problems will not be?
& is a C. language operator. Degree ... Well, for example, count how many times you need to divide the number by 2 to get zero :) Once again, you have a question. Tell me an algorithm for solving such problems . He prompted. - HarrySource: https://ru.stackoverflow.com/questions/633229/
All Articles