Word description Constructs an integer (bit field) from a series of values on the stack together with a bit field specifier, which is an array whose elements have one of the following shapes:
•
{ word shift } - word is applied to the top of the stack and the result is shifted to the left by shift bits and bitor'd with the bit field
•
shift - the top of the stack is shifted to the left by shift bits and bitor'd with the bit field
•
{ constant shift } - constant is shifted to the left by shift bits and bitor'd with the bit field
The bit field specifier is processed in order, so stack values are taken from left to right.
Examples Consider the following specification:
•
bits 0-10 are set to the value of x
•
bits 11-14 are set to the value of y
•
bit 15 is always on
•
bits 16-20 are set to the value of fooify applied to z
Such a bit field construction can be specified with a word like the following:
USING: math math.bitwise prettyprint ;
IN: math.bitwise.examples
: fooify ( x -- y ) 0b1111 bitand ;
: baz-bitfield* ( x y z -- n )
{
0
11
{ 1 15 }
{ fooify 16 }
} bitfield* ;
1 2 3 baz-bitfield* . 233473
Put a 1 at bit 1, put the 1 from the stack at bit 5, square the 3 and put it at bit 8: