The six--js bit operator exercises in the front-end learning notes

Source: Internet
Author: User
Tags binary to decimal decimal to binary

The job title is as follows:

--------------------------------------------------

Bit operators are not very familiar with this problem, just fill it up.

Decimal to Binary method: Divide the decimal number by 2 to take the first remainder, and then the quotient is divided by 2 continuously, taking the second and third ... Remainder until the quotient is 0 o'clock, then the first, second ... From right to left, high 0.

Binary to decimal method: Starting from the rightmost number of the binary number, from left to right, each digit is multiplied by 2 of the 0, 2 1, 2 2, and then the result is added, that is, the decimal number.

Therefore, this problem decimal 22 into the binary process: the remainder of the 22/2=11 is 0;11/2=5 remainder is the 1;5/2=2 remainder for the 1;2/2=1 remainder is the 0;1/2=0 remainder of 1. The binary of decimal 22 is 10110.

Decimal 3 to Binary procedure: 3/2=1 remainder is 1;1/2=0 remainder is 1. Decimal 3 is converted to binary 11.

In addition, the & operation, corresponding to the number of digits compared, there is a 0 is 0, two at the same time 1 to get 1.

So 10110&00011, the result of the operation is 00010, this is binary. The conversion to decimal is: 1*2 1 times the square +0 Times 2 of the 0 square = 2.

The six--js bit operator exercises in the front-end learning notes

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.