Java Reference
In-Depth Information
Table8-2
JavaBitwiseOperators
OPERATOR
ACTION
&
bitwiseAND
|
bitwiseOR
^
bitwiseXOR
~
bitwiseNOT
<
bitwiseleft-shift
>
bitwiseright-shift
>>
bitwiseunsignedright-shift
1AND0=0
1AND1=1
1OR0=1
NOT1=0
Atablethatlistsallpossibleresultsofabitwiseorlogicaloperationis
calleda truthtable . Table8-3 hasthetruthtablesforAND,OR,XOR,and
NOT. The tables are valid for both logical and the bitwise operations.
Table 8-3
Logical Truth Tables
AND
OR
XOR
NOT
000 000 000 01
010 011 011 10
100 101 101
111 111 110
When using logical and bitwise operators you must keep in mind that
although they perform similar functions, the logical operators do not
change the actual contents of the variables. The bitwise operators, on the
other hand, manipulate bit data. Thus, the result of a bitwise operation is
a variable with a value different from the previous one.
Programmers note:
Itiscustomarytonumberthebitsinanoperandfromright-to-leftwith
therightmostbitdesignatedasbitnumber0.Referto Figure3-2 .
 
Search WWH ::




Custom Search