本文实例讲述了golang简单位运算。分享给大家供大家参考,具体如下:
复制代码 代码如下:
// http://play.golang.org/p/idG7Ri_krU
package main
import "fmt"
func main() {
var n uint8 = 6
fmt.Printf("%s/n%08b/n%08b/n/n", "6<<1 左移1位", n, n<<1)
fmt.Printf("%s/n%08b/n%08b/n/n", "6>>1 右移1位", n, n>>1)
fmt.Printf("%s/n%08b/n%08b/n/n", "^6 位取反", n, ^n)
fmt.Printf("%s/n%08b/n%08b/n%08b/n/n", "6&5 位与", n, 5, n&5)
fmt.Printf("%s/n%08b/n%08b/n%08b/n/n", "6|5 位或", n, 5, n|5)
fmt.Printf("%s/n%08b/n%08b/n%08b/n/n", "6^5 位异", n, 5, n^5)
}
希望本文所述对大家Go语言程序设计有所帮助。