Next: Unary Binary Logic, Previous: Mingle, Up: Operators [Index]
INTERCAL-72 | C-INTERCAL | CLC-INTERCAL | J-INTERCAL |
---|---|---|---|
yes | all versions | all versions | all versions |
The select operator is one of the two binary operators in
INTERCAL-72; unlike mingle, every known implementation of
INTERCAL ever has used the sqiggle character
(~
) as the representation of the select operator, meaning
that writing it portably is easy.
The select operator takes two arguments, which can be of either
datatype (that is, 16- or 32-bit). It returns a value made by selecting
certain bits of its first operand indicated by the second operand, and
right-justifying them. What it does is that it ignores all the bits of
the first operand where the second operand has a 0 as the corresponding
bit, that is, deletes them from a copy of the operand’s value;
the bits that are left are squashed together towards the
least-significant end of the number, and the result is filled with 0s
to make it up to 16 or 32 bits. (In INTERCAL-72 the
minimum multiple of 16 bits possible that the result fits into is
chosen, although if :1 has the value 131061 (in hex, 1FFFF) the
expression #21~:1
produces a 32-bit result because 17 bits
were selected, even though many of the leading bits were zeros; in
C-INTERCAL the data type of the result is the same as of
the right operand of the select, so that it can be determined at
compile time, and so using a unary binary logic operator on the result
of select when the right operand has a 32-bit type is nonportable and
not recommended.) As an example, #21~:1
produces 21 as its
result if :1 has the value 131061, 10 as its result if :1 has the value
30 (1E in hex; the least significant bit of 21 is removed because it
corresponds to a 0 in :1), and 7 as its result if :1 has the value 21
(because three bits in 21 are set, and those three bits from 21 are
therefore selected by 21).
Select is used for right-shifts, to select every second bit from a number (either to produce what will eventually become an argument to mingle, or to interpret the result of a unary binary logic operator, or occasionally both), to test if a number is zero or not (by selecting it from itself and selecting 1 from the result), in some cases as a limited version of bitwise-and (that only works if the right operand is 1 less than a power of 2), and for many other purposes.
Next: Unary Binary Logic, Previous: Mingle, Up: Operators [Index]