mirror of
https://gitee.com/shikong-sk/golang-study
synced 2025-04-20 18:28:15 +08:00
docs: 运算符 基础
This commit is contained in:
parent
3cf7dd1550
commit
88e4c72f85
@ -41,4 +41,20 @@ func main() {
|
|||||||
fmt.Println("a>=b :", a >= b)
|
fmt.Println("a>=b :", a >= b)
|
||||||
fmt.Println("a<b :", a < b)
|
fmt.Println("a<b :", a < b)
|
||||||
fmt.Println("a<=b :", a <= b)
|
fmt.Println("a<=b :", a <= b)
|
||||||
|
|
||||||
|
fmt.Println("=========================================================")
|
||||||
|
|
||||||
|
// 位运算
|
||||||
|
// 5 & 2 = 0101 & 0010 => 0000
|
||||||
|
fmt.Printf("%d & %d => %d\n", 5, 2, 5&2)
|
||||||
|
// 5 | 2 = 0101 | 0010 => 0111
|
||||||
|
fmt.Printf("%d | %d => %d\n", 5, 2, 5|2)
|
||||||
|
// 5 ^ 2 = 0101 ^ 0010 => 0111
|
||||||
|
fmt.Printf("%d ^ %d => %d\n", 5, 2, 5^2)
|
||||||
|
// 左移 1 << 3 = 1 * 2^3 = 8
|
||||||
|
// 0001 => 1000
|
||||||
|
fmt.Printf("%d << %d => %d\n", 1, 3, 1<<3)
|
||||||
|
// 右移 8 >> 3 = 8 / 2^3 = 1
|
||||||
|
// 1000 => 0001
|
||||||
|
fmt.Printf("%d >> %d => %d\n", 8, 3, 8>>3)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user