-
Logical operator: -
Logical and( && or and ): used to determine whether multiple conditions are met at the same time. The result is true only when all conditions are true. -
Logical OR( || or or ): used to judge whether at least one of the multiple conditions is met. As long as any one of the conditions is true, the result is true. -
Logical negation( ! ): Used for reverse operation, to convert true to false and false to true.
Logical operators are mainly used to judge conditions in control flow statements (such as conditional statements and circular statements), and determine the execution path of the program according to the judgment results. -
-
Bit operator: -
Bit and( & ): Performs an AND operation on the corresponding bits of two operands. If the corresponding bits are both 1, the result is 1; Otherwise, it is 0. -
Bit or( | ): Perform or operation on the corresponding bit of two operands. If one of the corresponding bits is 1, the result is 1; Otherwise, it is 0. -
Allor( ^ ): XOR the corresponding bits of two operands. If the corresponding bits are the same, the result is 0; If different, the result is 1. -
Bitwise negation( ~ ): Reverse each bit of the operand, changing 0 to 1 and 1 to 0. -
Bit Shift Left( << ): Moves the binary representation of the operand to the left by the specified number of bits, which is equivalent to multiplying by the power of 2. -
Bit Shift Right( >> ): Move the binary representation of the operand to the right by the specified number of digits, which is equivalent to dividing by the power of 2 and rounding.
Bit operators are mainly used to directly operate binary data, such as processing bit fields, image processing, optimized storage and other scenarios that need to operate on the bottom bit. -