看帮助文档,搜其他东西,瞥到个示例,运行看了下效果:
没太多内容,就是简单记下
//64位机子的测试结果: //var s uint = 33 //var i = 1 << s // 1 has type int //var j int32 = 1 << s // 1 has type int32; j == 0 //var k = uint64(1 << s) // 1 has type uint64; k == 1<<33 //var m int = 1.0 << s //fmt.Println(i, j, k, m) // 8589934592 0 8589934592 8589934592 var s uint = 65 var i = 1 << s // 1 has type int var j int32 = 1 << s // 1 has type int32; j == 0 var k = uint64(1 << s) // 1 has type uint64; k == 1<<33 var m int = 1.0 << s fmt.Println(i, j, k, m) // 0 0 0 0 var a = make([]byte, 1.0<<s) // 1.0 has type int; len(a) == 0 if ints are 32bits in size fmt.Println(cap(a)) //0
也就是说对于32位的 类型,变量初值1的话,移33位后是0
对于64位的类型,变量初值1的话,移64位后也是0
这里说的是多少位的类型,可以是显式定义的,也可以如make函数里的,匹配参数形参类型的。