1、运算符
位移右操作数必须是无符号整数,或可以转换的无显示类型常量。
package main
func main() {
b := 23
x := 1 << b // 无效操作: 1 << b (shift count type int, must be unsigned integer)
println(x)
}
如果是非常量位移表达式,那么会优先将无显示类型的常量左操作数转型。
package main
import "fmt"
func main() {
a := 1.0 << 3 // 常量表达式 (包括常量展开)
fmt.Printf("%T, %v\n", a, a) // int, 8
var s uint = 3
b := 1.0 << s // invalid operation: 1 << s (shift of type float64)
fmt.Printf(