How to determine whether the right shift of a computer system is "logical right", or "arithmetic right shift"?

Source: Internet
Author: User
Tags arithmetic

The right and left shifts are different.

For the left, there is no "logical left" and "arithmetic left" the difference, the main difference here is the computer system according to the highest bit (that is, sign bit) is "1" or "0", supplementing "1" or "0"

Whether for the highest bit of unsigned number "1" or "0", the lowest bit of the left-shift total "0"

or for the symbol number symbol is positive "0" or negative "1", the lowest left position also all complement "0"


The difference is

The difference between "logic" and "arithmetic" is only when you move to the right.


How to test whether a computer system is "logically moving right" or "arithmetic right shift".

The answer is: you must use the highest level of "1" of the number of tests

If the number with the highest bit of "1" (here is represented by the full "1" sequence ~0) Move right:

A= (~0>>4);
if (a==~0) printf ("Computer system for Arithmetic right shift");
else printf ("Computer system is logically moving right");

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.