| Total Complexity | 9 |
| Total Lines | 22 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class PowerOfTwo |
||
| 8 | { |
||
| 9 | public static function isPowerOfTwo(int $n): bool |
||
| 10 | { |
||
| 11 | return $n > 0 && (($n & ($n - 1)) === 0); |
||
| 12 | } |
||
| 13 | |||
| 14 | public static function isPowerOfTwo2(int $n): bool |
||
| 15 | { |
||
| 16 | if ($n <= 0) { |
||
| 17 | return false; |
||
| 18 | } |
||
| 19 | while ($n % 2 === 0) { |
||
| 20 | $n /= 2; |
||
| 21 | } |
||
| 22 | |||
| 23 | return $n === 1; |
||
| 24 | } |
||
| 25 | |||
| 26 | public static function isPowerOfTwo3(int $n): bool |
||
| 29 | } |
||
| 30 | } |
||
| 31 |