Skip to content

Instantly share code, notes, and snippets.

@mediaupstream
mediaupstream / bitmask-crud.js
Last active November 8, 2021 12:34
Store CRUD settings in 2 bytes with bitmasks
const CREATE = 0
const READ = 1
const UPDATE = 2
const DELETE = 3
const add = (a, b) => a |= (1 << b)
const remove = (a, b) => a &= ~(1 << b)
const has = (a, b) => ((a & (1 << b)) > 0)
const bin = (a) => (s).toString(2)