How to use bitwise AND (&) in JavaScript

2 Answers

0 votes
const x = 6;        // 00000000000000000000000000000110
const y = 3;        // 00000000000000000000000000000011

console.log(x & y); // 00000000000000000000000000000010



/*
run:

2 

*/

 



answered Nov 12, 2020 by avibootz
0 votes
 function dec2bin(dec) {
      return (dec >>> 0).toString(2);
}

const x = 6;        // 00000000000000000000000000000110
const y = 7;        // 00000000000000000000000000000111

console.log(x & y); // 00000000000000000000000000000110


console.log(6, dec2bin(x));
console.log(7, dec2bin(y));
console.log("x & y", dec2bin(x & y));




/*
run:

6
6, "110"
7, "111"
"x & y", "110"

*/

 



answered Nov 12, 2020 by avibootz

Related questions

2 answers 406 views
1 answer 244 views
2 answers 325 views
1 answer 310 views
2 answers 294 views
294 views asked Feb 14, 2017 by avibootz
1 answer 236 views
236 views asked Jun 13, 2015 by avibootz
2 answers 351 views
...