Language basis of Go Operators
Operator for performing mathematical or logical operations at runtime.
Operators
Go operators are built into the language:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
Arithmetic operators
Operators | description |
---|---|
+ | Adding |
- | Subtraction |
* | Multiplied |
/ | Divided |
% | Remainder |
Note: ++
(increment) and --
(decrement) Go is a single statement in the language, not the operator.
Relational Operators
Operators | description |
---|---|
== | Check the two values are equal, equal returns True if otherwise False. |
!= | Check the two values are not equal, not equal returns True if otherwise False. |
> | Check the left value is greater than the right value, it returns True if it is otherwise False. |
>= | Check the left value is greater than or equal to the right value, it returns True if it is otherwise False. |
< | Check the left value is less than the right value, it returns True if it is otherwise False. |
<= | Check the left value is less than or equal to the right value, it returns True if it is otherwise False. |
Logical Operators
Operators | description |
---|---|
&& | Logical AND operator. If both sides of the operands are True, compared to True, otherwise False. |
|| | Logical OR operator. If the number of operations on both sides of a True, compared to True, otherwise False. |
! | Logical NOT operator. If the condition is True, it was False, otherwise True. |
Bitwise Operators
Bitwise operators of integer bits in the memory operation.
Operators | description |
---|---|
& | And two binary phase number corresponding to each of the participating operation. (Only two are 1 to 1) |
| | Two involved in computing the number corresponding to the respective binary or phase. (Two have a 1 on 1) |
^ | Two involved in computing the number corresponding to the respective binary or different, when two dissimilar corresponding binary, the result is 1. (Two are not the same, compared with 1) |
<< | N-bit left shift is multiplied by the power of n 2. "A << b" is the whole of a respective binary b-bit left shift, the high discard, low 0s. |
>> | Right by n bits is divided by 2 ^ n. "A >> b" is a whole to the right of each binary bit b. |
Assignment Operators
Operators | description |
---|---|
= | Simple assignment operator, will assign a value of the expression of an lvalue |
+= | Added together before assignment |
-= | After subtraction assignment |
*= | By multiplying assignment |
/= | Division after assignment |
%= | Remainder after assignment |
<<= | Left after the assignment |
>>= | Right after the assignment |
&= | Bitwise and after the assignment |
|= | After pressing position or assignment |
^= | After pressing bit XOR assignment |