C + + base-bit operations

Source: Internet
Author: User

Yesterday, the written test encountered a problem, so that the multiplication of the calculation method, design and optimization, and then summarize the relevant knowledge of the bit operations are as follows:

In the computer, the data is stored in 1010 binary form, 1bytes = 8 Bits,bit is a bit, so bit operation is to each 1010 operation.

Bitwise operations have &|~^<<>>, respectively, with or non-XOR or left shift right.

With: 1 with unchanged, 0 with for 0;

Or: only 0 or 0 is 0, other cases are 1;

Non: Take the reverse;

XOR: The same is 0, the difference is 1;

Shift left: Move several digits to the left/right;

Multiplication:

Move left one bit, equivalent to X2;

Division:

Shift right One bit,/2;

You do not need to apply for a third variable to achieve the exchange of 2 variable values:

Because a^b^a==b

So there are:

A=a^b;

B=a^b;

A=a^b;

C + + base-bit operations

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.