js实现位运算
2021-02-16 13:20
标签:push 实现 java asc xxx highlight console amp pre js实现位运算 标签:push 实现 java asc xxx highlight console amp pre 原文地址:https://www.cnblogs.com/cxyzj/p/12971639.html const arr = [2,4,16];
let v = 0;
for(const i in arr) v |= arr[i];
console.log(v);
let xxx = 23;// 16 4 2
let r = [];
let i = 0;
while (xxx > 0) {
const x = xxx & Math.pow(2, i);
if (x) {
xxx -= x;
r.push(x);
}
i++;
}