Skip to content

Instantly share code, notes, and snippets.

@leodutra
Last active December 21, 2015 15:37
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 leodutra/87edf2e92360c9797513 to your computer and use it in GitHub Desktop.
Save leodutra/87edf2e92360c9797513 to your computer and use it in GitHub Desktop.
Fast fill bits from right - JavaScript bitwise function
function fillBitsFromRight(n) { // http://jsperf.com/fill-bits-bitwise-vs-alternatives
return ~(-1 << n); // ~(~0 << n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment