js实现位运算

 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++; }

  

相关文章