Swap Variables using Bitwise Operators Java Program

Java Program To Swap Variables using Bitwise Operators

Here’s a Simple Program To Swap Variables using Bitwise Operators in Java Programming Language. This Java Program To Swap Two Numbers makes use of only Two Variables and doesn’t use any Third or Temporary Variable.


What are Bitwise Operators?

Bitwise Operators are specifically used in Digital Computer Programming. Such operators can be used to manipulate the Bits or Binary Digits in a given Integer. It works upon Byte-Level tasks that makes use of Bitwise Operators.

Example:

& represents Binary AND
| represents Binary OR
<< represents Binary Left Shift
^ represents Binary XOR

Also Read: Java Code To Swap Two Variables without using Temporary Variable


Java Program To Swap Two Variables using Bitwise Operators

Output

Swap Variables using Bitwise Operators in Java Programming Language

In case you have any doubt about Bitwise Operators or if you get any Compilation Errors in this Java Program To Swap Variables using Bitwise Operators, let us know about it in the Comment Section below.

Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

Join The Discussion