How to use bitwise AND assignment (&=) in JavaScript

2 Answers

0 votes
function dec2bin(dec) {
      return (dec >>> 0).toString(2);
}

let x = 7;        // 00000000000000000000000000000111
const y = 5;      // 00000000000000000000000000000101

console.log(x &= y); // 00000000000000000000000000000101


console.log(5, dec2bin(x));
console.log(5, dec2bin(y));





/*
run:

5
5, "101"
5, "101"

*/

 



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

let x = 3;        // 00000000000000000000000000000011
const y = 5;      // 00000000000000000000000000000101

console.log(x &= y); // 00000000000000000000000000000001


console.log(1, dec2bin(x));
console.log(5, dec2bin(y));




/*
run:

1
1, "1"
5, "101"

*/

 



answered Nov 12, 2020 by avibootz

Related questions

2 answers 180 views
1 answer 157 views
1 answer 259 views
1 answer 237 views
2 answers 230 views
1 answer 223 views
2 answers 202 views
202 views asked Feb 14, 2017 by avibootz
...