Last active
December 26, 2019 06:58
-
-
Save Williammer/709b0c7ead146fdfb6a92102c1a04c8a to your computer and use it in GitHub Desktop.
Some basic functions for the bitwise operations
This file contains 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
// right shift of 0 makes the num unsigned: https://stackoverflow.com/questions/9939760/how-do-i-convert-an-integer-to-binary-in-javascript | |
const numToBinary(num) => (n >>> 0).toString(2); | |
const lowBit = (n) => n & -n; // returns the sub-number which is the last 1 in binary of the original number | |
// low Bit operation is used in "Binary indexed Trees" | |
// https://zh.wikipedia.org/zh-hans/%E6%A0%91%E7%8A%B6%E6%95%B0%E7%BB%84 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment