InferenceAI

Enter at least two characters to search.

Start free

Power of Two Check

easyBit Manipulation15 min10 XP

Return True if n is a power of two (n=2kn = 2^k for some integer k≥0k \ge 0).

Requirements

  • One expression: a power of two has exactly one set bit, so n & (n - 1) == 0.

Examples

EXAMPLE WALKTHROUGHtwo to the zero

A guided view of the published example, not a trace of your code.

INPUT[1]
TASKpower_of_two_check()
EXPECTED OUTPUTtrue

Start with the input values shown in this example.

Example 1 of 3

Input: n = 1

Output: true

Explanation: two to the zero

Input: n = 16

Output: true

Explanation: sixteen

Input: n = 3

Output: false

Explanation: not a power

Hint 1

Remember to reject n <= 0.

Topics

DSABit ManipulationPython