Math Fundamentals18 sections · 814 units
Open in Course

Power of Two - Algorithm

(Loop until n becomes 1)

1.1. If n ≤ 0, return false.

2.2. While n > 1: if n mod 2 ≠ 0, return false. Otherwise divide n by 2.

3.3. If you exit the loop with n = 1, return true.