js bitwise operation All In One
js bitwise operation All In One
js 位运算
&
按位
与
AND
|
按位
或
OR
`^
按位
异或
/ 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/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13533318.html
未经授权禁止转载,违者必究!