The shift operator for JavaScript operators

Source: Internet
Author: User
Tags bitwise operators

Today in the work in JS see >>> Such a thing do not know and have not seen in other places.

Check the data on the Internet to know this is an operator called the unsigned Right shift operator, the name is very long also difficult to understand, is related to the binary.

If there is a right, there must be a left, that is <<<.

For example: 100 of the binary is 01100100 to the right to move two bits is 00011001 and this number in the back decimal is 25.

Do not know how to convert between these can go to Baidu algorithm or directly on the Internet to find such an application, of course, this is not important thing we need to know what this operator is for. He's just so simple. Though the name looks professional, it's just a bit of a move.

Similar to this are the bitwise operators, << bitwise LEFT and >> bitwise right-shift operators. As the name implies, move one to the left and move to the right. The difference between him and the front is:

If the number is positive when the displacement is calculated, after the displacement in front of 0, negative, then after the displacement in front of 1

Cases

100>>2==25 is the same as the above calculation method

If 100 is a negative number

-100>>>2

-the binary of the 100 is-_-good length.

1111111111111111111111111111111111111111111111111111111111111100

After removing the last 2 digits

11111111111111111111111111111111111111111111111111111111111111

Then two bits in front

1111111111111111111111111111111111111111111111111111111111111111

Turns into a decimal result is-1

So

-100>>>2=-1.

But I found in the use of a small trick, such as 100>>2 ==25, which we have tried, we can understand this 100 divided by 2 2, that is, 100/2/2==25, this is our junior high school math will be.

That in turn 100<<2 is 100 times 2 of the 2-time Square is also 400.

This is not a good understanding of much.

These are the places where personal understanding must be inappropriate and wrong.

The shift operator for JavaScript operators

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.