Introduction to Javascript bitwise AND operator (&) _ basic knowledge

Source: Internet
Author: User
Javascript bitwise AND operator (& amp;) is used to perform bitwise "and" operations on two 32-bit expressions. Generally, the expressions are decimal integers, in this case, you need to first convert it to the corresponding binary, and then add 0 to the forward to supplement the 32-bit The Code is as follows:


Result = [integer 1] & [integer 1]

& Perform the bitwise "and" operation on each bit of two 32-bit expressions. If both bits are 1, the result is 1. Otherwise, the result is 0.

Bit 1 Bits 2 Bitwise AND
0 0 0
1 1 1
0 1 0
1 0 0
The following example shows how to use the & bitwise AND operator and the & = bitwise AND value assignment operator:

The Code is as follows:


// 9 the binary value is 1001, and the 32-bit complement value is 00000000000000000000000000001001.
Var expr1 = 9;

// 5 is 00000000000000000000000000000101
Var expr2 = 5;

/*
00000000000000000000000000001001
&
00000000000000000000000000000101
=
00000000000000000000000000000001
=
1
*/

Var result = expr1 & expr2;

Alert (result );
// [1] is displayed]

Expr1 & = expr2;
Alert (expr1 );
// [1] is displayed]

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.