zoukankan      html  css  js  c++  java
  • go 运算符

    
    //参考 https://blog.csdn.net/weixin_42100098/article/details/80142523
    
    
    package main
     
    import "fmt"
     
    func main()  {
    	/*
    	 位运算符:将数值转为二进制,按位操作
    	&:按位与,都为1才为1,有一个为0就为0
    	|:按位或,都为0才为0,有衣蛾为1就为1
    	^:异或操作,不同为1,相同为0
    	<<:左移, A << B,将A转为二进制,向左移动B位
    		相当于A*2的B次方
    	>>:右移,A >> B,向右移动B位
    	 */
    	 a := 60
    	 b := 13
     
    	 /*
    	 60=32+16+8+4
    	 13=8+4+1
    	 a: 0011 1100
    	 b: 0000 1101
    	 &: 0000 1100
    	 |:0011 1101
    	 ^:0011 0001
    	  */
    	res1 := a & b
    	res2 := a | b
    	res3 := a ^ b
    	 fmt.Println(res1) // 12
    	 fmt.Println(res2) // 61
    	 fmt.Println(res3) // 49
    	 fmt.Printf("%b,%b
    ", a, b)
     
    	 /*
    	 b = 13
    	 b:  0000 1101
    	 <<2:00 110100  = 32+16+4
    	 >>2:0000 0011
    	  */
    	  res4 := b << 2
    	  b = 13
    	  res5 := b >> 2
    	  fmt.Println(res4, res5)
    
    
    
    
  • 相关阅读:
    git学习
    Command Line
    python之测试
    python之模块
    python之函数
    python之类
    python之错误和异常
    python之迭代器和生成器
    python之字典和集合
    python之列表和元组
  • 原文地址:https://www.cnblogs.com/lajiao/p/11579666.html
Copyright © 2011-2022 走看看