answersLogoWhite

0

void swap (int *a, int *b) {

*a ^= *b;

*b ^= *a;

*a ^= *b;

return;

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

How you can interchange two integer values using swap variable in c language?

t = a; a = b; b = t; // t is a third integer variable (swap variable) But here's a way without a swap variable, given as as a macro in C: #define SWAP(a,b) { if (a!=b) { a^=b; b^=a; a^=b; }} // Swap macro by XOR Once you define it, you can say swap(x,y) to swap x and y. The numbers kind of flow through each other and end up swapped.


How do you write a javascript to swap two numbers without using third one?

By using the algorithm of bitwise EORing (Exclusive ORing) the numbers together:If the two numbers are X and Y, then to swap them:X = X EOR YY = Y EOR XX =X EOR Ywill swap them.With knowledge of that algorithm, one then uses the syntax of Javascript to implement it.


How can you devise a way to interchange two variables A and B without using a third variable or register using Exclusive OR?

A = A xor B B = A xor B A = A xor B in C... A^=B; B^=A; A^=B;


What gate can be used to constructed full adder?

A full adder can be constructed using basic logic gates: XOR, AND, and OR gates. Specifically, two XOR gates are used to calculate the sum, while two AND gates and one OR gate are employed to determine the carry-out. The first XOR gate takes the two input bits, and the second XOR gate incorporates the carry-in. The AND gates handle the carry generation, with the OR gate combining the outputs to produce the final carry-out.


How do you represent assignment by bitwise XOR operator?

The bitwise XOR operator is ^, or shift 6. The bitwise XOR assignment operator is ^=.

Related Questions

How do you swap two numbers with bitwise operator in c plus plus?

// Note: ^ is the XOR operator a = a ^ b b = b ^ a a = a ^ b


How do you swap two variables using bitwise operators?

a := a XOR b b := a XOR b a := a XOR b it works, but never use it in real programs do you know why its not used in real program??


How do you write a program in C to swap two variables without using the third one using XOR?

a=a^b; b=a^b; a=a^b;


How you can interchange two integer values using swap variable in c language?

t = a; a = b; b = t; // t is a third integer variable (swap variable) But here's a way without a swap variable, given as as a macro in C: #define SWAP(a,b) { if (a!=b) { a^=b; b^=a; a^=b; }} // Swap macro by XOR Once you define it, you can say swap(x,y) to swap x and y. The numbers kind of flow through each other and end up swapped.


Swapping without third variable?

There are two ways in which you can swap without a third variable. 1. Using xor operation swap( int *a, int *b) { *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b; } 2. Using addition and subtraction swap( int *a, int *b) { *a = *a + *b; *b = *a - *b; *a = *a - *b; } }


Write a program to swap two numbers using function?

swap (int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; }


How many xor gates required for 4 bit parity checker?

3*xor- two input


How to swap two numbers by call by reference in c plus plus?

void swap(int& a, int& b ) { a^=b^=a^=b; }


Swap two numbers using call by value and call by reference?

You cannot swap two numbers using call by value, because the called function does not have access to the original copy of the numbers.Swap with call by reference... This routine uses exclusive or swap without temporary variable.void swap (int *a, int *b) {*a ^= *b;*b ^= *a;*a ^= *b;return;}


Is xor gate is a universal gate?

No, XOR gate is a not a universal gate. There are basically two universal gates NAND and NOR.


How do you write a javascript to swap two numbers without using third one?

By using the algorithm of bitwise EORing (Exclusive ORing) the numbers together:If the two numbers are X and Y, then to swap them:X = X EOR YY = Y EOR XX =X EOR Ywill swap them.With knowledge of that algorithm, one then uses the syntax of Javascript to implement it.


What is it called when you swap the two numbers that you multiply?

I don't know.the Switch-A-Roo? not,it's inverse.