Skip to content

Bit-string functions

Bit-string functions operate on ANY_BIT values (BOOL, BYTE, WORD, DWORD, LWORD). Shift/rotate functions take a bit count N : ANY_INT. The boolean operators are also available as the AND / OR / XOR / NOT keywords.

FunctionParametersReturns
SHLIN : ANY_BIT, N : ANY_INTANY_BIT
SHRIN : ANY_BIT, N : ANY_INTANY_BIT
ROLIN : ANY_BIT, N : ANY_INTANY_BIT
RORIN : ANY_BIT, N : ANY_INTANY_BIT
ANDIN : ANY_BIT (2+ args)ANY_BIT
ORIN : ANY_BIT (2+ args)ANY_BIT
XORIN : ANY_BIT (2+ args)ANY_BIT
NOTIN : ANY_BITANY_BIT

Shift IN by N bit positions; vacated bits are filled with zeros.

SHL(IN : ANY_BIT, N : ANY_INT) : ANY_BIT
SHR(IN : ANY_BIT, N : ANY_INT) : ANY_BIT
doubled := SHL(value, 1); // multiply by 2
high := SHR(packed, 8); // move the high byte down

Rotate IN by N positions; bits shifted out one end re-enter the other.

ROL(IN : ANY_BIT, N : ANY_INT) : ANY_BIT
ROR(IN : ANY_BIT, N : ANY_INT) : ANY_BIT
rotated := ROL(pattern, 1);

AND, OR and XOR are variadic (two or more inputs) and combine the inputs bit by bit.

AND(IN : ANY_BIT, ...) : ANY_BIT // 2+ args
OR(IN : ANY_BIT, ...) : ANY_BIT // 2+ args
XOR(IN : ANY_BIT, ...) : ANY_BIT // 2+ args
both := AND(statusA, statusB);
either := OR(flagsA, flagsB);
changed := XOR(previous, current);
NOT(IN : ANY_BIT) : ANY_BIT
inverted := NOT(mask);