// 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:"); ...
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 ...
The following example demonstrates swapping two integers using the XOR bitwise operator: packagemainimport"fmt"funcmain(){varnum1int=10varnum2int=20fmt.Println("Numbers before swapping:")fmt.Println("Num1: ",num1)fmt.Println("Num2: ",num2)// Swapping using XOR bitwise operatornum1=num1^num...
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 - Calculate X^N (X topower of N) using pow function C - Find difference of two numbers C - Print size of variables using sizeof() operator C - Demonstrate examples of escape sequences C - Find area & perimeter of circle C - Find area of a rectangle C - Calculate HCF of two ...
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...
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...
C - Calculate HCF of two numbers C - Multiply two numbers using plus operator C - Demonstrate example of global & local scope C - Demonstrate example of floor & ceil functions Write a C - Evaluatenet salary of an employee givenfollowing constraints C - Swap two numbers W/O using a tempo...