C # shift operator (1)

Source: Internet
Author: User

C # section of the shift operator (1)

Left shift operator (<)
Move the first operand to the left and the number of digits specified by the second operand. For example, 1100100 <2 = 110020.,1100100 shifted left to 1100100 ports, and 110010000 after 0.

Right Shift Operator (<)
Move the first operand to the right to the number of digits specified by the second operand, and fill in 0 for the null position. For example: 1100100> 2 = 0011001,1100100 after the right shift of two digits, the mouth is 11001, and after 0 is filled, the mouth is 0011001.

Interesting things
In the decimal system, the Left shift is equivalent to adding a 0, that is, increasing the first square of 10, and the left shift is adding two zeros, that is, expanding the second square of 10. Similarly, in the binary system, a 0 value is added to shift the first digit to the left, that is, the doubling of the first digit of 2 is increased, and the two digits to the left are added with two zeros, Which is doubled by the second element of 2, then there is the following relationship:

N <1, equivalent to n * 2
N <2, equivalent to n * 4
N <3, equivalent to n * 8
N <4, equivalent to n * 16

Similarly, the right shift is expressed:

N> 1, equivalent to n/2
N> 2, equivalent to n/4
N> 3, equivalent to n/8
N> 4, equivalent to n/16

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.