Home > Article > Backend Development > 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 (==, !=, 95ec6993dc754240360e28e0de8de30a, d2e24fbfa3a7d998970671c0359d3643=): 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 (&, |, ^, <95ec6993dc754240360e28e0de8de30a>): 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 (907db452713800afb7c3fa2f8585d48c>): 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!