Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
swap two float variables via xor
#include <cstdio>
void swap(int & a, int & b)
{
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
int main()
{
float a = 1.1, b = 2.3;
swap(*(int*)&a, *(int*)&b);
printf("%f\t%f\n", a, b);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.