Skip to content

Instantly share code, notes, and snippets.

@Tsugami
Last active June 9, 2021 20:59
Show Gist options
  • Save Tsugami/98b7a446d8922b43947c3152458dd080 to your computer and use it in GitHub Desktop.
Save Tsugami/98b7a446d8922b43947c3152458dd080 to your computer and use it in GitHub Desktop.
export const hasBit = (bit, bitfield) => (bitfield & bit) === bit;
export const addBit = (bit, bitfield) => bitfield | bit;
export const removeBit = (bit, bitfield) => bitfield & ~bit;
export const addOrRemoveBit = (bit, bitfield) => addBit(bit, bitfield) ? removeBit(bit, bitfield) : addBit(bit, bitfield);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment