Go 位运算符

此生再无相见时 提交于 2019-12-06 09:56:57

Go 位运算符

package main



import "fmt"



func main() {

   var a uint = 60  /* 60 = 0011 1100 */  

   var b uint = 13  /* 13 = 0000 1101 */

   var c uint = 0          



   c = a & b       /* 12 = 0000 1100 */

   fmt.Printf("Line 1 - Value of c is %d\n", c )



   c = a | b       /* 61 = 0011 1101 */

   fmt.Printf("Line 2 - Value of c is %d\n", c )



   c = a ^ b       /* 49 = 0011 0001 */

   fmt.Printf("Line 3 - Value of c is %d\n", c )



   c = a << 2     /* 240 = 1111 0000 */

   fmt.Printf("Line 4 - Value of c is %d\n", c )



   c = a >> 2     /* 15 = 0000 1111 */

   fmt.Printf("Line 5 - Value of c is %d\n", c )

}

本文转自:http://codingdict.com/article/23571

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!