Bit Selection Operator ([])

The [] operator selects a subset of the bits of its operand. Either a single bit offset or a range of bits may be specified. Bit offsets are zero based, where the zeroth bit is the least significant bit of the value.

Examples

x[0] := a[1];
x[2..0] := a[3..1];
x[2..0] := (a+b*c)[3..1];
x := a[s..t];
a[s..t] := x;

Reversed ranges

If the range is reversed, then the bits in the result are also reversed.

// Reverse selection
x[0..1] := a[1..0];          // x[0] = a[1], x[1] = a[0]
x[2..0] := a[0..2];          // x[2] = a[0], x[1] = a[1], x[0]=a[2]

// NOT reverse selection, but valid syntax
x[0..2] := a[2..4];

// Also valid syntax, and reverse selection too.
x[2..0] := (a + b)[0..2];

Multiple ranges

A list of ranges and bit offsets separated by commas may also be specified to select several values and concatenate them.

INT littleEndian := 0x1234;
INT bigEndian;

bigEndian[15..0] := littleEndian[7..0, 15..8];