This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why int variable as it be decleared can't used Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why int variable as it be decleared can Watch "Why int variable as it be decleared can New topic
Author

Why int variable as it be decleared can't used " ^ " with number?

Hades Pan
Ranch Hand

Joined: Nov 25, 2001
Posts: 106
FOR EXP: int i=2^2;
Will print 0
Jim Hall
Ranch Hand

Joined: Nov 29, 2001
Posts: 162
The "^" does not mean raise the number to a power. It is the exclusive or (XOR) operator.
<code>
0000 0010 // 2
0000 0010 // 2
---------
0000 0000 // 0
</code>
With XOR
0 ^ 0 -> 0
0 ^ 1 -> 1
1 ^ 0 -> 1
1 ^ 1 -> 0
Another example:
<code>
0001 0101 // 21
0010 1101 // 45
---------
0011 1000 // 56
</code>
Hades Pan
Ranch Hand

Joined: Nov 25, 2001
Posts: 106
I got is
Thans Jim Hall~~!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why int variable as it be decleared can't used " ^ " with number?
 
Similar Threads
operators
why "int aNumber (any shift operator) -ve number " gives 0
Generalized formula for producing numbers from Math.random()?
operator precedence and associativity
help