Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bitwise operator

 
wei Qiao
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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).
Thanks!
Wei
PS. I am planning to take the test this Friday.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic