Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
function GetBits(value){
  var b = 1;
  var res= [];
  while(b<=value){
    if(b & value)res.push(b);
    b <<= 1;
  }
  return res;
}
console.log(GetBits(129));
console.log(GetBits(77));
console.log(GetBits(255));
Output 300px

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers