yphastos
8/1/2017 - 7:12 PM

swap Adjacent Bits

swap Adjacent Bits

function swapAdjacentBits(n) {
  return ((n & 0xaaaaaaaa) >> 1) | ((n & 0x55555555) << 1);
}

function swapAdjacentBits(n) {
  return x = 2863311530, n/2 & x/2 | 2*n & x;
}

function swapAdjacentBits(n) {
  return (n >> 1 & 0x55555555) | (n << 1 & 0xAAAAAAAA) ;
}