Java Reference
In-Depth Information
In Chapter 2 you learned about Java's arithmetic, relational, and logical operators. Al-
though these are the most commonly used, Java provides additional operators that expand
the set of problems to which Java can be applied: the bitwise operators. The bitwise op-
erators can be used on values of type long , int , short , char , or byte . Bitwise operations
cannot be used on boolean , float , or double , or class types. They are called the bitwise op-
erators because they are used to test, set, or shift the individual bits that make up a value.
Bitwise operations are important to a wide variety of systems-level programming tasks in
which status information from a device must be interrogated or constructed. Table 5-1 lists
the bitwise operators.
Table 5-1 The Bitwise Operators
The Bitwise AND, OR, XOR, and NOT Operators
The bitwise operators AND, OR, XOR, and NOT are & , |, ^, and ~. They perform the same
operations as their Boolean logical equivalents described in Chapter 2 . The difference is
that the bitwise operators work on a bit-by-bit basis. The following table shows the out-
come of each operation using 1's and 0's:
 
Search WWH ::




Custom Search