Bitwise operator.
Bitwise operators are rarely used in shell scripts..Their main purpose seems to be to operate and test from sockets
Read variables. "Bit flipping" is closely related to the compilation language , for example, C/C ++ , in this language, it can
Run fast enough.,I checked,It seems that there is nothing to do.,I don't understand)
<Shifts 1 to the left (2 is required for each left shift)
<= Move a few places left,= The number of digits to be left behind
Let "Var <= 2" means to shift two places to the left (that is, multiply by 4)
> Shift 1 to the right (remove 2 for each right shift)
>>= Shifts the right digit
& Bitwise AND
& = Bitwise AND value assignment
| By bit or
| = By bit or value
~ Non-bitwise
! By bit? (I don't understand ~ What is the difference ?),It seems that it should be placed in the logical operation below
^ Bitwise OR XOR
^ = XOR or assignment
Logical operation:
& Logic and
1 If [$ condition1] & [$ condition2]
2 # Same as: If [$ condition1-A $ condition2]
3 # If both condition1 and condition2 are true,The result is true.
4
5 if [[[$ condition1 & $ condition2] # yes.
6 # Note & not allowed to appear in.
Note: & can also be used in and list (see Chapter 25),However, it depends on the context.
| Logical or
1 If [$ condition1] | [$ condition2]
2 # Same as: If [$ condition1-o $ condition2]
3 # If condition1 or condition2 is true,The result is true.
4
5 if [[$ condition1 | $ condition2] # Yes
6 # Note | it cannot appear in.
Note: Bash connects each test to the exit status of the logical operation.
Example:
If ["$ A"-EQ 24] & ["$ B"-EQ 47] And if ["$ A"-EQ 24-a "$ B"-EQ 47] to get the same result.
A = 1
Let "A = A | 0x4"
Echo $
If [$ (A | 0x4)-EQ 5]; then
Echo "ADA"
Fi
Original article:
Http://blog.csdn.net/zhrmghl/article/details/1346409