Problem solving with programming: Checking if a number is power of 2
Given an integer how do we check if it is a power of 2?For example 1, 2, 4, 8, 16, 32, 64, 128, 256,... are integral powers of 2.
There are several methods to check if a number is a power of 2.
Method#1: Using repeated division
If you repeatedly divide the number by 2 (without any remainder), You will finally get a 1 if it is a power of two.
Read full article from Problem solving with programming: Checking if a number is power of 2
No comments:
Post a Comment