what is << iota in Go
tags: learning go programming
content
- in go-bitmask-check, im seeing this code:
type RowLineFlags int
const (
Revision RowLineFlags = 1 << iota
Highlightable
Elided
)- what does
<< iotado?- this is
iotawith bit shift operator<<to create a set of flags with distinct bit patterns 1 << iotameans the flags only has one bit turned on- it’s a constant with a single bit turned on, like
0x01, 0x02, 0x04, etc - i.e.: in binary
- it’s a constant with a single bit turned on, like
- this is
Revision = 0001 (binary)
Highlightable = 0010 (binary)
Elided = 0100 (binary)- and in decimal
Revision = 1
Highlightable = 2
Elided = 4