Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

const powers of 2

  • iota
package main

import (
	"fmt"
)

const (
	one = 1 << iota
	two
	four
	eight
	sixteen
)

func main() {
	fmt.Println(one)
	fmt.Println(two)
	fmt.Println(four)
	fmt.Println(eight)
	fmt.Println(sixteen)

	fmt.Println()
	fmt.Println(two | eight)
}
1
2
4
8
16

10