What are the operators in Go language?
The operators in Go language are: 1. Addition operator; 2. Subtraction operator; 3. Multiplication operator; 4. Division operator; 5. Remainder operator; 6. Comparison operator ; 7. Bitwise operator; 8. Bitwise AND operator; 9. Bitwise OR operator; 10. Bitwise XOR operator; 11. Left shift operator; 12. Right shift operator. Detailed introduction: 1. Addition operator, used to perform the addition operation of two values; 2. Subtraction operator, used to perform the subtraction operation of two values; 3. Multiplication operator, used to perform the multiplication operation of two values etc.
The operating system for this tutorial: Windows 10 system, DELL G3 computer.
The Go language contains a variety of operators for performing various mathematical and logical operations. The following are some common Go language operators and their uses:
1. Addition operator ( ): is used to perform the addition operation of two values.
a := 5 b := 3 sum := a + b // 8
2. Subtraction operator (-): is used to perform the subtraction operation of two values.
a := 10 b := 3 difference := a - b // 7
3. Multiplication operator (*): is used to perform multiplication of two values.
a := 5 b := 3 product := a * b // 15
4. Division operator (/): is used to perform the division operation of two values.
a := 10 b := 2 quotient := a / b // 5
5. Remainder operator (%): is used to perform the remainder operation of two values, that is, to find the remainder of division.
a := 10 b := 3 remainder := a % b // 1
6. Comparison operators (==, !=, <, >, <=, >=): Used to compare whether two values are equal or not Equality, or whether one value is less than, greater, less than or equal to, or greater than or equal to another value.
a := 5 b := 3 if a == b { fmt.Println("a equals b") // false } else if a > b { fmt.Println("a is greater than b") // true } else { fmt.Println("a is less than b") // false }
7. Bitwise operators (&, |, ^, <<, >>): are used to operate on the binary bits of integers, such as bitwise AND , bitwise OR, bitwise XOR, left shift and right shift.
a := 60 // 0011 1100 in binary b := 13 // 0000 1101 in binary c := a & b // 12, 0000 1100 in binary d := a | b // 61, 0011 1101 in binary e := a ^ b // 49, 0011 0001 in binary f := a << 2 // 240, 1111 0000 in binary (left shift by 2) g := a >> 2 // 15, 0000 1111 in binary (right shift by 2)
8. Bitwise AND operator (&): performs an AND operation on the binary bits of two integers. Only when the two corresponding binary bits are both 1, the result The corresponding binary bit is 1.
9. Bitwise OR operator (|): Perform an OR operation on the binary bits of two integers. As long as one corresponding binary bit is 1, the corresponding binary bit of the result will be is 1.
10. Bitwise XOR operator (^): Performs an XOR operation on the binary bits of two integers. When the two corresponding binary bits are different, the corresponding binary number of the result bit is 1.
11. Left shift operator (<<): Shift the binary bits of an integer to the left by the specified number of digits, and fill the right side with zeros. The left shift operation is equivalent to multiplying by the specified power of 2.
12. Right shift operator (>>): Shift the binary bits of an integer to the right by the specified number of digits, filling the left side with the sign bit (for signed integers) . The right shift operation is equivalent to dividing by the specified power of 2.
The above is the detailed content of What are the operators in Go language?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The library used for floating-point number operation in Go language introduces how to ensure the accuracy is...

Queue threading problem in Go crawler Colly explores the problem of using the Colly crawler library in Go language, developers often encounter problems with threads and request queues. �...

What should I do if the custom structure labels in GoLand are not displayed? When using GoLand for Go language development, many developers will encounter custom structure tags...

The problem of using RedisStream to implement message queues in Go language is using Go language and Redis...

The difference between string printing in Go language: The difference in the effect of using Println and string() functions is in Go...

Two ways to define structures in Go language: the difference between var and type keywords. When defining structures, Go language often sees two different ways of writing: First...

Which libraries in Go are developed by large companies or well-known open source projects? When programming in Go, developers often encounter some common needs, ...

Resource management in Go programming: Mysql and Redis connect and release in learning how to correctly manage resources, especially with databases and caches...
