Skip to content

Instantly share code, notes, and snippets.

@Williammer
Last active December 26, 2019 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Williammer/709b0c7ead146fdfb6a92102c1a04c8a to your computer and use it in GitHub Desktop.
Save Williammer/709b0c7ead146fdfb6a92102c1a04c8a to your computer and use it in GitHub Desktop.
Some basic functions for the bitwise operations
// 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