Javascript right-shift 0-bit effect

Source: Internet
Author: User

The right-hand 0-bit in Javascript can be used to quickly remove decimals and define the displacement operation:

The right-shift operation is to move the operand of a bits to the right by the number of bits specified to move it, move out the bit to be discarded, or fill the left-hand position with 0, or fill the sign bit.

Actually look at the effect:

32.5 >> 0//32

What is the function of right shift?

(+). ToString (' 2 ')//converted to 2 binary, resulting in 100000

(>> 1). toString (2)//1-bit right shift, get 10000

By contrast:

100000//Actual value 32

010000//Actual value 16

How to get rid of decimal place?

32.5 >>1 << 1

or directly

32.5 >> 0

Javascript right-shift 0-bit effect

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.