PLAYGROUND (experimental)

bit_insert

Inserts val into n at bit positions [low, high] inclusive.
bit_insert(
    n, 
    val, 
    low, 
    high, 
    [format="dec"], 
    [zeropad=0]
) -> NUMBER

Inserts val into n at bit positions [low, high] inclusive.

Syntaxe

var result = bit_insert(8, 7, 0, 2);  // Returns 15 (binary 1000 -> insert 111 at bits 0-2 = 1111)

Arguments

NameTypeRequiredDefaultDescription
nyes-Number (int/float), hex string (0x... #...), or binary string (0b...)
valyes-Value to insert
lowyes-Lowest bit position (inclusive)
highyes-Highest bit position (inclusive)
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