Propeller Manual

Table Of Contents
Operators – Spin Language Reference
Bitwise Decode ‘|<
The Bitwise Decode operator decodes a value (0 – 31) into a 32-bit long value with a single
bit set high corresponding to the bit position of the original value. Bitwise Decode can be
used in variable and integer constant expressions, but not in floating-point constant
expressions. Example:
Pin := |<PinNum
The above example sets Pin equal to the 32-bit value whose single high-bit corresponds to the
position indicated by
PinNum.
If
PinNum is 3, Pin is set equal to %00000000 00000000 00000000 00001000.
If
PinNum is 31, Pin is set equal to %10000000 00000000 00000000 00000000.
There are many uses for Bitwise Decode, but one of the most useful is to convert from an I/O
pin number to the 32-bit pattern that describes that pin number in relation to the I/O registers.
For example, Bitwise Decode is very handy for the mask parameter of the
WAITPEQ and
WAITPNE commands.
Bitwise Decode becomes an assignment operator when it is the sole operator to the left of a
variable on a line by itself. For example:
|<PinNum
This would store the decoded value of PinNum back into PinNum.
Bitwise Encode ‘
>|
The Bitwise Encode operator encodes a 32-bit long value into the value (0 – 32) that
represents the highest bit set, plus 1. Bitwise Encode can be used in variable and integer
constant expressions, but not in floating-point constant expressions. Example:
PinNum := >|Pin
The above example sets PinNum equal to the number of the highest bit set in Pin, plus 1.
If
Pin is %00000000 00000000 00000000 00000000, PinNum is set equal to 0; no bits are set.
If
Pin is %00000000 00000000 00000000 10000000, PinNum is set equal to 8; bit 7 is set.
If
Pin is %10000000 00000000 00000000 00000000, PinNum is set equal to 32; bit 31 is set.
If
Pin is %00000000 00010011 00010010 00100000, PinNum is set equal to 21; bit 20 is the
highest bit set.
Page 160 · Propeller Manual v1.1