Skip to content

Instantly share code, notes, and snippets.

@shhider
Created May 19, 2020 09:51
Show Gist options
  • Save shhider/da03ecae67308b450ef486d6e943749b to your computer and use it in GitHub Desktop.
Save shhider/da03ecae67308b450ef486d6e943749b to your computer and use it in GitHub Desktop.
[Bit Operator] #javascript

To test if a bit is set:

if ((mask & flag) != 0) {
  // bit is set
} else {
  // bit is not set
}

To set a bit:

mask |= flag;

To clear a bit:

mask &= ~flag;

To toggle a bit:

mask ^= flag;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment