Last active
May 3, 2021 10:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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