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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
n | yes | - | Number (int/float), hex string (0x... #...), or binary string (0b...) | |
val | yes | - | Value to insert | |
low | yes | - | Lowest bit position (inclusive) | |
high | yes | - | Highest bit position (inclusive) | |
format | - | "dec" | Output format: 'dec', 'hex', or 'bin' | |
zeropad | - | 0 | Zero-pad hex/bin output to this width in bits (8, 16, 32, 64), 0 for no padding |