Home Backend Development Golang What are the operators in Go language?

What are the operators in Go language?

Dec 22, 2023 pm 02:44 PM
go language operator

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What libraries are used for floating point number operations in Go? What libraries are used for floating point number operations in Go? Apr 02, 2025 pm 02:06 PM

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

What is the problem with Queue thread in Go's crawler Colly? What is the problem with Queue thread in Go's crawler Colly? Apr 02, 2025 pm 02:09 PM

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? What should I do if the custom structure labels in GoLand are not displayed? Apr 02, 2025 pm 05:09 PM

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...

How to solve the user_id type conversion problem when using Redis Stream to implement message queues in Go language? How to solve the user_id type conversion problem when using Redis Stream to implement message queues in Go language? Apr 02, 2025 pm 04:54 PM

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

In Go, why does printing strings with Println and string() functions have different effects? In Go, why does printing strings with Println and string() functions have different effects? Apr 02, 2025 pm 02:03 PM

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

What is the difference between `var` and `type` keyword definition structure in Go language? What is the difference between `var` and `type` keyword definition structure in Go language? Apr 02, 2025 pm 12:57 PM

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 provided by well-known open source projects? Which libraries in Go are developed by large companies or provided by well-known open source projects? Apr 02, 2025 pm 04:12 PM

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, ...

In Go programming, how to correctly manage the connection and release resources between Mysql and Redis? In Go programming, how to correctly manage the connection and release resources between Mysql and Redis? Apr 02, 2025 pm 05:03 PM

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

See all articles