PLAYGROUND (experimental)

bit_shift

Shifts bits left or right with specified mode, width, and output format.
bit_shift(
    n, 
    count, 
    [mode="arithmetic"], 
    [width=8], 
    [format="dec"], 
    [zeropad=0]
) -> STRING

Shifts bits left or right with specified mode, width, and output format.

Syntaxe

var result = bit_shift(5, 1);                    // Default: arithmetic, default width, decimal
var result2 = bit_shift(5, -1, "circular", 0, "hex", 8);  // Circular, auto-width, hex, zero-pad to 8
var result3 = bit_shift(5, 1, "logical", 8, "bin", 8);  // Binary: "00001010"

Arguments

NameTypeRequiredDefaultDescription
nyes-Number (int/float), hex string (0x... #...), or binary string (0b...)
countyes-Positions to shift (positive=left, negative=right)
mode-"arithmetic"Shift mode: 'logical', 'arithmetic', 'circular'
width-8Bit width (8, 16, 32, 64...), or 0 for auto-detect
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