du8980919 2017-08-01 09:05
浏览 206
已采纳

在Go语言中,为什么“ << 0”运算将得到1?

I am quite confused about the go left shift operator. I run the following code:

package main

func main(){
    var x = 1 << 0
    println(x)
}

And I get 1. But I think the result should be zero.

  • 写回答

1条回答 默认 最新

  • doudu5498 2017-08-01 09:10
    关注

    1 << 0 means:

    Take 1 and don't shift it. The result should be the original number: 1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?