Skip to content

Instantly share code, notes, and snippets.

@lqt0223
Created April 9, 2017 12:02
Show Gist options
  • Save lqt0223/8944e96d55f93d76885dccaaddcda02d to your computer and use it in GitHub Desktop.
Save lqt0223/8944e96d55f93d76885dccaaddcda02d to your computer and use it in GitHub Desktop.
19 Bitwise operation and utilities
// bitwise operation and utilities
// Left shift by 1, will multiply the number by 2
console.log(2 << 1); // return 4
// Right shift by 1, will divide the number by 2.
// In JavaScript, the decimal part will be floored
console.log(2 >> 1); // return 1
console.log(3 >> 1); // return 1
// Bitwise AND by 1, will return 0 for even number and odd for even number
console.log(2 & 1); // return 0
console.log(3 & 1); // return 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment