bit_extract
Extracts bits from n in the range [low, high] inclusive.
bit_extract(
n,
low,
high,
[format="dec"],
[zeropad=0]
) -> NUMBER
Extracts bits from n in the range [low, high] inclusive.
Syntaxe
var result = bit_extract(13, 1, 3); // Returns 5 (binary 1101 -> extract bits 1-3 = 101)
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
n | yes | - | Number (int/float), hex string (0x... #...), or binary string (0b...) | |
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 |