Change uncertainty to confirmation ~ Everything is always "two" (what is the use of bitwise operations in C)

Source: Internet
Author: User

Back to directory

In this article, "2" refers to binary, that is, when we see 2, it is also called every two, and it is the simplest and clearest data. In real life, the most commonly used data is decimal data, that is, every 10 to one. Let's take a look at the example:

Binary: decimal

0 0

01 01

10 02

11 03

100 04

As you can see, in binary, there will be no numbers greater than 1, except that 0 is 1, but in decimal, there will be no 10, which is from 0 ~ 9.

In our C #, bitwise operations are divided into left displacement and right displacement, which are represented by <and> respectively. The left shift is equivalent to the Left shift, and the right side is supplemented with 0, for example:

10 <1 it means 10 0, and the final result is 100, which is equivalent to 4 in decimal order. At this time, it is difficult to see that the value shifted to 1, which is equivalent to a multiplication of 2, there is also a right shift, for example:

100> 1. The result is 010. It is supplemented with 0 on the left side. After the right shift, it is equivalent to the operation except 2.

With this feature, we can do this when designing the flags feature enumeration with a location.

 

Let's take a look at its value output.

The result is as follows:

Conclusion: In fact, in decimal, hexadecimal or octal bitwise operations, the calculator converts the bitwise operation to binary, and then calculates the displacement.

Back to directory

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.