02. Arithmetic left shift logic left shift, arithmetic right shift logic right shift

Source: Internet
Author: User
Tags arithmetic
 1. Arithmetic left shift logic left

The arithmetic left shift and the logical left shift are the right 0:

Like 00101011.

Shift arithmetic left one: 01010110

Shift logic left one: 01010110

For binary values, the left-shift n-bit equals the original value multiplied by 2 of the n-th square.

For example, 110,100 binary is 26, left two digits after 011010 00 turn to decimal is 104 times 26.

PS: This multiple relationship only applies if the left-hand post-abandoned high position does not contain 1, otherwise it overflows.


2. Arithmetic right shift, logical right SHIFT

Logical right shift is simple, as long as the binary number is moved to the right, the left 0 can be

such as 10101101 logical right shift one to 01010110

The arithmetic right shift symbol bit is moved together, and the symbol bit on the left side, that is, if the sign bit is 1, the 1 sign bit is 0, 0

For example: 11100 arithmetic right Shift one is 11110 (sign bit 1 moves along and complements 1 on the left)

For binary values, the right shift n is equal to the original value divided by 2 of the n-th square.

For example, 101.101 million binary is 76 (you need to convert this complement to the original code and then converted to decimal), the right shift two digits after 11101101 turns to decimal is 19 is 76 times.

PS: This multiple relationship is only applicable to the less right operand after the removal of the low 1 of the situation, otherwise each 1 represents the remainder is discarded, the whole number of parts.

Pay attention to ... Here the binary is the complement, because the computer is in the complement of the operation, the above examples are positive so the complement and the same as the original code, if it is negative to pay attention to the need to first convert the complement to the source code to convert to decimal

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.