Skip to content

Instantly share code, notes, and snippets.

@ahsankhatri
Created February 6, 2017 07:32
Show Gist options
  • Save ahsankhatri/95dbe2732b89c99713534dfe7de01095 to your computer and use it in GitHub Desktop.
Save ahsankhatri/95dbe2732b89c99713534dfe7de01095 to your computer and use it in GitHub Desktop.
Check if number is a power of 2
<?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