function valueAtBit(n, bit) {
  let arr = [];
  while (n > 0) {
    arr.push(n%2);
    n = Math.floor(n / 2);
  }
  
  return arr[bit-1]; 
}