package main import ( "fmt" ) const anetNone uint8 = 0 const ( anetPreRel uint8 = 1 << iota anetUnstable anetExperiment anetBeta = anetPreRel | anetUnstable anetAlpha = anetBeta | anetExperiment ) var ( // In Golang, a byte is exactly equivalent to a uint8. // Use the same value extracted in the example `extractversion.go`. // A value of 0x01 (1) indicates Pre-Release flag is set, with no other myFlags set. myFlags byte = 0x01 ) func main() { fmt.Printf("Flags:\t%d\t%#02x\n\n", myFlags, myFlags) // Prints: /* Flags: 1 0x01 */ for flag, flagNm := range map[uint8]string{ anetPreRel: "Pre-release", anetUnstable: "Unstable", anetExperiment: "Experimental", anetBeta: "Beta release", anetAlpha: "Alpha release", } { fmt.Printf( "Has flag '%s' (%d, %#02x):\t%v\n\n", flagNm, flag, flag, myFlags&flag == flag, ) } // Prints: /* Flags: 1 0x01 Has flag 'Pre-release' (1, 0x01): true Has flag 'Unstable' (2, 0x02): false Has flag 'Experimental' (4, 0x04): false Has flag 'Beta release' (3, 0x03): false Has flag 'Alpha release' (7, 0x07): false */ }