Skip to content

Instantly share code, notes, and snippets.

@GeekaholicLin
Created December 31, 2016 03:02
Show Gist options
  • Save GeekaholicLin/0b74f2674d4036baa1576222612a4af0 to your computer and use it in GitHub Desktop.
Save GeekaholicLin/0b74f2674d4036baa1576222612a4af0 to your computer and use it in GitHub Desktop.
判断是否是2的幂次
function isTwoS(input){
  var result = input&(input-1);
  console.log(result===0);
}
isTwoS(8);

使用按位与进行判断。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment