What are the operators in Go language?

百草
Release: 2023-12-22 14:44:47
Original
849 people have browsed it

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.

What are the operators in Go language?

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
Copy after login

2. Subtraction operator (-):is used to perform the subtraction operation of two values.

a := 10 b := 3 difference := a - b // 7
Copy after login

3. Multiplication operator (*):is used to perform multiplication of two values.

a := 5 b := 3 product := a * b // 15
Copy after login

4. Division operator (/):is used to perform the division operation of two values.

a := 10 b := 2 quotient := a / b // 5
Copy after login

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
Copy after login

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 }
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!