setBit

setBit(integer x, integer bit, [integer value]) → integer result

Returns the number number with the bit at position position set to value (1 by default). The original number is not modified.

Position 0 is the least significant bit. The function also works on big integers.

Example:

setBit(0, 3)      // 8:  sets bit 3 to 1   (1000 in binary)
setBit(15, 1, 0)  // 13: sets bit 1 to 0   (1101 in binary)
Math.setBit(0, 3)     // 8:  sets bit 3 to 1   (1000 in binary)
Math.setBit(15, 1, false) // 13: sets bit 1 to 0 (1101 in binary)
Math.setBit(0, 3)      # 8:  sets bit 3 to 1   (1000 in binary)
Math.setBit(15, 1, False)  # 13: sets bit 1 to 0 (1101 in binary)
Parameters
Return
Note