function updateBit2(n, i, b) {
  const mask = ~(1 << i);
  return (n & mask) | (b << i);
}
Set bit to either 1 or 0

It first clear the bit with a mask and then set it to whatever b is.

@param n number
@param i index
@param b bit either 0 or 1. If bigger than 1 value will overflow
@returns {number} new number with a given bit set/cleared