Content deleted Content added
Iridescent (talk | contribs) m Cleanup and typo fixing, typo(s) fixed: 1980's → 1980s |
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags |
||
Line 24:
number won't divide by 2 evenly; if the only factor left is 1, the original number was a power of 2. Using bit and logical operators, there is a simple expression which will return true (1) or false (0):
<
bool isPowerOfTwo = x && !(x & (x - 1));
</syntaxhighlight>
The second method uses the fact that powers of two have one and only one bit set in their binary representation:
|