E
Eric Sosman
Merrill said:Now that everyone's had their fun with Floyd's discomfiture, and the thread
is starting to drift, I wanted to ask a *somewhat* similar question, in that
it involves bit manipulations. I do not, however, have a T.A.
In K&R2 §2.9 appears the following sentence: The bitwise OR operator | is
used to turn bits on:
x=x | SET_ON;
sets to one in x the bits that are set to one in SET_ON.
I've looked in the index and the usual header files, and I find nothing on
SET_ON. I am no longer subject to the admonition to read K&R sequentially,
as I am doing so presently and am past this point. MPJ
K&R Classic (I don't have the New Testament) uses the
identifier MASK instead of SET_ON. Neither identifier is
in any way "special" to C, and neither is predefined in a
header or elsewhere. If you want to set the low-order bit
you'd provide a SET_ON or MASK of 1. If you want to set
the three low-order bits you'd use 7:
Original x = 00101010 binary = 42
SET_ON = 00000111 binary = 7
Result = 00101111 binary = 47
Each bit in the final `x' is a one if it was already a one
or if SET_ON's corresponding bit is a one, or is a zero if
both `x' and SET_ON had a zero at that position. Another
(and equivalent) view is that each bit in the final `x' is
a one if SET_ON has a one at that position, or is unchanged
if SET_ON has a zero.