When I was chatting with my colleague, my colleague suddenly asked me what was the difference between using one & and two && symbols in IF judgment, and I was suddenly confused, forgetting whether to use one & symbol as and condition, or two && symbols as and conditions.Correct is in IF logic judgment and is using two && symbols。
Bit operators are faster than ordinary arithmetic operators, and can perform some functions that arithmetic operators cannot. If you want to develop efficient programs, bit operators are essential. Bit operators are used to manipulate binary bits, including: bitwise and (&), bitwise or (|), bitwise or (^), bitwise inverse (~), bitwise shift (<<), bitwise shift (>>). & is bitwise and, meaning it works at the bit level. && is a logical with, meaning it works at the Boolean (true/false) level. Logic and the use of short circuits (If the first part is false, it is useless to check the second part) to prevent running too much code,And by bit and need to operate on each bit to determine the result。
The sample code is as follows:
It can be seen that when using the && symbol, if the first one is false, the second judgment will not be executed, while when using the & symbol, although the first one is false, the obvious result must be false, but the second judgment method will still be executed.
(End)
|