js bitwise operation all in one_jsjs bitwise operation all in one 位运算 进制转换



js bitwise operation all in one

位运算

&

按位与



|

按位或



^

按位异或 / XOR

let a = 5;      // 00000000000000000000000000000101
a ^= 3; // 00000000000000000000000000000011
console.log(a); // 00000000000000000000000000000110

let b = 5; // 00000000000000000000000000000101
b = b ^ 3; // 00000000000000000000000000000011
console.log(b); // 00000000000000000000000000000110
// 6



js bitwise operation all in one_js

​https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR_assignment​

~

按位取反/按位非



>>

按位右移



<<

按位左移

const a = 5;         // 00000000000000000000000000000101
const b = 2; // 00000000000000000000000000000010
console.log(a << b); // 00000000000000000000000000010100
// 20

const x = 5; // 00000000000000000000000000000101
const y = 3; // 00000000000000000000000000000011
console.log(x << y); // 00000000000000000000000000101000
// 40
(5 << 3).toString(2)
// "101000"
parseInt("101000", 2)
// 40


js bitwise operation all in one_javascript_03

​https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift​

refs

位运算(&、|、^、~、>>、<<)

​https://www.runoob.com/w3cnote/bit-operation.html​



xgqfrms