Home > Web Front-end > JS Tutorial > body text

Introduction to the use of Javascript bitwise AND operator (&)_Basic knowledge

WBOY
Release: 2016-05-16 17:01:29
Original
987 people have browsed it

Copy code The code is as follows:

result = [Integer 1] & [Integer 1]

& 对两个 32 位表达式的每一个位执行按位“与”运算。 如果两个位均为 1,则结果是 1。 否则,结果为 0。

位1 位2 位与
0 0 0
1 1 1
0 1 0
1 0 0
The following example demonstrates how to use the & bitwise AND operator and the &= bitwise AND assignment operator:

Copy code The code is as follows:

// 9 Binary is 1001, the complement of 32 bits is 00000000000000000000000000001001
var expr1 = 9;

// 5 is 000000000000000000000000000101
var expr2 = 5;

/*
0000000000000000000000000001001
& >00000000000000000000000000000101
=
000000000000000000000000000000001
=
1
*/

var result = expr1 & expr2;

alert(result);
// popup【1】

expr1 &= expr2;
alert(expr1);
//pop-up【1】

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!