// Rust program to swap two numbers// using bitwise XOR (^) operatorfnmain() {letmutnum1:i32=6;letmutnum2:i32=2; println!("Numbers before swapping:"); println!("\tNum1: {}",num1); println!("\tNum2: {}",num2); num1=num1^num2; num2=num1^num2; num1=num1^num2; pri...
The source code toswap two numbers using the Bitwise XOR (^) operatoris given below. The given program is compiled and executed successfully. // Swift program to swap two numbers using// bitwise XOR (^) operatorimport Swift; var num1=5; var num2=8; print("Numbers before swapping:"); ...
Java Program to Swap Two Number Using Bitwise XOR operator Java class Swap { public static void main(String[] args) { int a = 11, b = 22; System.out.println("Before swapping the numbers:"); System.out.println("First number = " + a); System.out.println("Second number = " + b...
XOR the two numbers again and store the result in the first number (x = 2 ^ 5 so x = 7)Below is the program to swap two numbers using bitwise operator.#include<stdio.h> #include<conio.h> void main() { int x = 6, y = 4; x = x^y; y = x^y; x = x^y; printf("x ...
Numbers before swapping: Num1: 10 Num2: 20 Numbers after swapping: Num1: 20 Num2: 10 Approach 3: Using XOR Bitwise Operator You can also use an advanced approach to swapping two numbers is by using the XOR bitwise operator. Example ...
1) Swapping two numbers using third variable To swap two values, there is a simple approach is using a temporary variable that stores the element for swapping. Algorithm Let, variableacontains first value, variablebcontains second value andtempis the temporary variable. ...
C - Get remainder W/O using % operator C - Convert ascii to integer (atoi implementation) C - Print ASCII table C - Swap two numbers using four different methods C - Check a given character is alphanumeric C - Check a given character is a digit C - Check a given character is a wh...
Java program to swap two numbers using bitwise operator Java program to find the highest bit set for a given integer number Java program to check if all the bits of a given integer number are HIGH or not Java program to count the total HIGH bits in the given number Java program to check...
Java program to swap two numbers using bitwise operator Java program to find the highest bit set for a given integer number Java program to check if all the bits of a given integer number are HIGH or not Java program to count the total HIGH bits in the given number Java program to check...
#include<iostream>usingnamespacestd;unsignedintswap_odd_even(intnum){intmask=0xAAAAAAAA;//A in hexadecimal is equal to 10 in decimal//and 1010 in binaryunsignedintoddbits=(num&mask);//right shift for even bitsunsignedintevenbits=num&(mask>>1);//can also use 0x55555555 as mask for even...