Skip to content

Instantly share code, notes, and snippets.

@massahud
Last active May 3, 2021 10:17
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 massahud/796fd3601f7d67e3b1c29b571d129161 to your computer and use it in GitHub Desktop.
Save massahud/796fd3601f7d67e3b1c29b571d129161 to your computer and use it in GitHub Desktop.
Bitmask using iota in go. Playground link: https://play.golang.org/p/jKuDcNVt-iK
package main
import "fmt"
const (
A int8 = 1 << iota
B
C
)
func main() {
on := A | C
if A&on > 0 {
fmt.Println("A is on")
}
if B&on > 0 {
fmt.Println("B is on")
}
if C&on > 0 {
fmt.Println("C is on")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment