Java Reference
In-Depth Information
In terms of its most common usage, you can think of the bitwise AND as a way to turn
bits off. That is, any bit that is 0 in either operand will cause the corresponding bit in the
outcome to be set to 0. For example:
The following program demonstrates the & by turning any lowercase letter into upper-
case by resetting the 6th bit to 0. As the Unicode/ASCII character set is defined, the lower-
case letters are the same as the uppercase ones except that the lowercase ones are greater
in value by exactly 32. Therefore, to transform a lowercase letter to uppercase, just turn off
the 6th bit, as this program illustrates:
The output from this program is shown here:
The value 65,503 used in the AND statement is the decimal representation of 1111 1111
1101 1111. Thus, the AND operation leaves all bits in ch unchanged except for the 6th one,
which is set to 0.
Search WWH ::




Custom Search