Swap Variables using Bitwise Operators Java Program

By | March 1, 2016

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.

Let's Discuss