-
-
Save grim-reapper/bc85cfdea99409e28bad9c77a5305c9a to your computer and use it in GitHub Desktop.
Check if number is a power of 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isPowerOfTwo($num) | |
{ | |
return ($num > 0) && (($num & ($num - 1)) == 0); | |
} | |
// var_dump(4); | |
// var_dump(5); | |
// var_dump(6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment