# Swap two numbers using bitwise operators

## Problem Statement:- Program to swap two numbers using bitwise operators.

#### Sample Input/Output:-

 Sample Input First:1721 Sample Output First: 2117 Sample Input Second: 3372 Sample Output Second: 7233

#### Data requirement:-

Input Data:- num1, num2

Output Data:-num1, num2

Program in C

Code:

Program in C++

## Here is the source code of the C++ Program to swap two numbers using bitwise operators.

Code:

### import java.util.Scanner;public class SwapTwoNumber {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        /* Get the two numbers input */        System.out.print("Enter the Two Numbers:");        int num1 = sc.nextInt();        int num2 = sc.nextInt();        /* Swaping two numbers using bitwise XOR operators. */        num1 = num1 ^ num2; /* ^(XOR operators) */        num2 = num1 ^ num2;        num1 = num1 ^ num2;        System.out.print("After Swapping two Numbers are:\nNumber1= " + num1 + "\nNumber2= " + num2);        sc.close();    }}Input/Output:Enter the Two Numbers:51 99After Swapping two Numbers are:Number1= 99Number2= 51

Program in Python

Code: