Created
April 9, 2017 12:02
-
-
Save lqt0223/8944e96d55f93d76885dccaaddcda02d to your computer and use it in GitHub Desktop.
19 Bitwise operation and utilities
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
// 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