Announcements and Reminders
|
Recording I/O ManipulatorsThe std manipulatorsWrite your own manipulatorData at the Bit LevelExample 8-1 – Primitive data at the bit level Example 8-2 – Non-primitive data at the bit level Bitwise Operators& operatorThe bitwise and operator returns a 1 only when both bits being compared are 1. For example: | operatorThe bitwise or operator returns a 1 only when either bits being compared are 1. For example: ^ operatorThe bitwise exclusive or operator returns a 1 only when either, but not both, bits being compared are 1. For example: ~ operatorThe
bitwise not, or complement operator is a unary bitwise operator.
It returns a 1 when the bit is 0 and returns a 0 when the bit is
1. For example: << operatorThe
bitwise left-shift operator shifts bits to left the number of positions
as the right-hand operand. Bits on the right are filled with
zeros. Bits on the left are lost. The left-shift operator
may be used to perform multiplication by integer powers of two.
For example, >> operatorThe
bitwise right-shift operator shifts bits to right the number of
positions as the right-hand operand. Bits on the left are filled
with zeros. Bits on the right are lost. The left-shift
operator may be used to perform division by integer powers of
two. For example, The bitwise assignment operatorsThe
bitwise assignment operators: &=, |=, ^=, <<=, and
>>= perform the implied operation and assign the resultant value
to the left-hand argument. Bitwise TechniquesTurn a bit onUse the or assignment bitwise operator to turn a bit on. If the bit is already turned on, the operation has no effect. Turn a bit offUse
the and assignment with the not bitwise operators to turn a bit
off. If the bit is already turned on, the operation has no effect. Toggle a bitUse the exclusive or assignment operator to turn a bit off. Test a bitUse the and operator to see if a bit is turned on. Integer_value & bit Example 8-4 – Bitwise operator techniques |