JavaScript logical operators

Source: Internet
Author: User
Tags bitwise logical operators

JS Bitwise AND ( & )

0001

&

0011

---

0001

A value of only two is 1 o'clock, which returns 1

JS Bitwise XOR or (^)

0101 (expression1)
1100 (expression2)
----
1001 (Result)

This bit of the result is 1 if and only if there is a bit on one expression that is 1 o'clock. Otherwise the result of this bit is 0.

JS bitwise OR (| )

0001

|

0011

0011

As long as one of the two numbers is 1, the result is 1, and the other is 0.

Bitwise non- (~)

Bitwise non-is to seek binary anti-code:

var num = 1; Binary 00000000000000000000000000000001

var num1 = ~num; Binary 11111111111111111111111111111110

We know that the numbers in JS are signed by default. The highest bit of the signed 32-bit binary means that the first digit is positive or negative, 1 represents a negative number, and 0 represents an integer. 11111111111111111111111111111110How much is that? The highest bit is 1 for negative numbers, and the binary for negative numbers is converted to decimal: The sign bit is unchanged, the other bits are reversed plus 1. After the inverse 10000000000000000000000000000001 , plus 1 10000000000000000000000000000010 , the decimal is-2.

JavaScript logical operators

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.