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

  

posted @ 2020-05-27 11:39  丿风轻灬云淡  阅读(216)  评论(0编辑  收藏  举报