Shell bit operator

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.