PLAYGROUND (experimental)

bit_set

Set the bit at position pos of the number n to val (0 or 1).
bit_set(
    n, 
    pos, 
    val, 
    [format="dec"], 
    [zeropad=0]
) -> NUMBER

Set the bit at position pos of the number n to val (0 or 1).

Syntaxe

var n = bit_set(144, 0, 1);

Arguments

NameTypeRequiredDefaultDescription
nyes-Number (int/float), hex string (0x... #...), or binary string (0b...)
posyes-Position
valyes-0 or 1
format-"dec"Output format: 'dec', 'hex', or 'bin'
zeropad-0Zero-pad hex/bin output to this width in bits (8, 16, 32, 64), 0 for no padding