Power of Two Checker
Enter a decimal or binary integer and instantly check whether it is an exact power of two. See the exponent, binary form, set-bit count, and nearest lower and higher powers of two.
What Is a Power of Two?
A power of two is a positive integer that can be written exactly as
2ⁿ, where n is a nonnegative integer.
The sequence begins with 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, and continues indefinitely. Each value is twice the previous power.
The number 1 is included because 2⁰ = 1. Zero and negative
integers are not powers of two under this standard definition.
How to Use the Power of Two Checker
Is 1024 a Power of Two?
Yes. The integer 1024 can be represented exactly as
2¹⁰.
How to Recognize a Power of Two in Binary
Every positive power of two has an especially simple binary pattern: exactly one bit is 1 and every other bit is 0.
| Decimal | Power | Binary | Set Bits |
|---|---|---|---|
| 1 | 2⁰ | 1 | 1 |
| 2 | 2¹ | 10 | 1 |
| 4 | 2² | 100 | 1 |
| 8 | 2³ | 1000 | 1 |
| 16 | 2⁴ | 10000 | 1 |
| 32 | 2⁵ | 100000 | 1 |
The x AND (x − 1) Power-of-Two Test
One of the most common bitwise methods for testing a positive integer is
to calculate x & (x − 1).
A positive power of two contains exactly one set bit. Subtracting one changes that set bit to zero and makes all lower bits one. The two values therefore have no set bit in common.
Why 12 Is Not a Power of Two
The decimal number 12 has binary representation 1100. It
contains two set bits instead of one.
Finding the Exponent of a Power of Two
If a number is an exact power of two, its exponent is equal to the zero-based position of its only set bit.
For example, binary 100000 has its only set bit at position
5, so the corresponding decimal value is 2⁵ = 32.
Finding the Nearest Lower and Upper Powers of Two
When a positive integer is not an exact power of two, it lies between two consecutive powers.
For example, 1000 lies between 512 and 1024. Therefore its nearest bounding
powers are 2⁹ = 512 and 2¹⁰ = 1024.
This calculator reports both bounding values so you can quickly determine the next smaller and next larger power-of-two boundary.
Common Powers of Two Table
| Exponent | Power of Two | Binary |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 2 | 10 |
| 2 | 4 | 100 |
| 3 | 8 | 1000 |
| 4 | 16 | 10000 |
| 5 | 32 | 100000 |
| 6 | 64 | 1000000 |
| 7 | 128 | 10000000 |
| 8 | 256 | 100000000 |
| 9 | 512 | 1000000000 |
| 10 | 1024 | 10000000000 |
| 16 | 65536 | 1 followed by 16 zeros |
| 20 | 1048576 | 1 followed by 20 zeros |
| 30 | 1073741824 | 1 followed by 30 zeros |
Are Zero, One, and Negative Numbers Powers of Two?
Is 0 a power of two?
No. There is no nonnegative integer exponent n for which
2ⁿ = 0.
Is 1 a power of two?
Yes. One is 2⁰, so it is the smallest positive integral
power of two.
Is −8 a power of two?
No under the standard positive-integer definition used by this checker.
Although its absolute value is 8, the number −8 itself is not equal to
2ⁿ for any nonnegative integer n.
Power of Two and Population Count
Population count measures how many 1 bits appear in a binary integer. A positive integer is an exact power of two precisely when its popcount is one.
This gives another useful way to understand the property without using logarithms or division.
Why Powers of Two Are Important in Computing
Binary-oriented capacities and boundaries are often naturally expressed using powers of two.
A single-bit mask is itself a power of two because exactly one bit is set.
Some hash tables, ring buffers, and low-level structures use power-of-two capacities for efficient indexing.
Memory and binary alignment boundaries frequently use values such as 2, 4, 8, 16, 32, or larger powers.
Power-of-two dimensions have historically been common in textures, buffers, and other computer graphics resources.
Many optimized integer algorithms rely on the predictable binary pattern of powers of two.
Common Power-of-Two Checking Mistakes
Forgetting that 1 is a power of two
Since 2⁰ = 1, the number 1 must return true.
Allowing zero through the bitwise test
A test using only x & (x − 1) requires a separate
x > 0 condition because zero needs special handling.
Using floating-point logarithms for huge integers
Floating-point logarithms can introduce precision problems for sufficiently large values. This checker instead uses exact integer logic.
Confusing even numbers with powers of two
Every positive power of two greater than one is even, but most even numbers are not powers of two. For example, 6, 10, and 12 are all even but are not powers of two.