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
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
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift
refs
位运算(&、|、^、~、>>、<<)
https://www.runoob.com/w3cnote/bit-operation.html
js 进制转换
https://www.cnblogs.com/xgqfrms/p/13532592.html
^
https://www.cnblogs.com/xgqfrms/p/13526984.html
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!