PLAYGROUND (experimental)

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

NameTypeRequiredDefaultDescription
nyes-Number (int/float), hex string (0x... #...), or binary string (0b...)
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