Skip to content

Instantly share code, notes, and snippets.

@bbengfort
Created July 26, 2019 19:33
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 bbengfort/12bf9343313e0211af7566fe2649ac34 to your computer and use it in GitHub Desktop.
Save bbengfort/12bf9343313e0211af7566fe2649ac34 to your computer and use it in GitHub Desktop.
type Bitmask uint8
const (
F0 bitmask = 1 << iota
F1
F2
)
func Set(b, flag Bitmask) Bitmask { return b | flag }
func Clear(b, flag Bitmask) Bitmask { return b &^ flag }
func Toggle(b, flag Bitmask) Bitmask { return b ^ flag }
func Has(b, flag Bitmask) bool { return b&flag != 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment