File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Bitwise operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Bitwise operator" Watch "Bitwise operator" New topic

Bitwise operator

wei Qiao

Joined: Jun 19, 2000
Posts: 23
What type does bitwise operator &, ^, | take? I know thet take integer(that's what is said on Robert's book). Also It takes boolean( even "true" and "false" keywords).
PS. I am planning to take the test this Friday.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
When used with integer primitive values, | & and ^ are bitwise operations, when used with boolean they are of course boolean.
In integer expressions, both sides are promoted to int or to long if one is long before the bitwise operation is carried out.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The bitwise operators can operate on all INTEGRAL types and not only int. as u said.In addition they can also be used with boolean literals(true and false).In that case true is treated as 1 and false as 0.The result is of type boolean.
I agree. Here's the link:
subject: Bitwise operator
It's not a secret anymore!