Tutorial 9


Bitwise Operators are used to perform bit by bit operation on the data in C++. They are Bitwise AND (&), Bitwise OR(|), Bitwise exclusive OR (^), Bitwise 1’s compliment (~). Bitwise operators apply only to char, int and long variables but not to floating-point data. 1&1 is 1, 1&0 is 0, 0&1 is 0, 0&0 is 0. 1|1 is 1, 1|0 is 1, 0|1 is 1, 0|0 is 0. 1^1 is 0, 1^0 is 1, 0^1 is 1, 0^0 is 0. ~1 is 0, ~0 is 1. Compound bitwise operators are used to assign a bitwise operator value to a variable. &=, |=, ^= are compound bitwise AND, inclusive OR, exclusive OR assignment operators. Bitwise shift operator is used to shift the bits in the bits or binary equivalent of a number with the number of bits provided to be shifted. << is Bitwise left shift operator and >> is bitwise right shift operator. 11100011 shifting left three bits will become 111-00011-000. Similar to compound bitwise operator, compound bitwise shift operator is provided to assign the bitwise shift value of/to the variable. <<= is compound bitwise left shift operator and >>= compound bitwise right shift operator.