Skip to content

Instantly share code, notes, and snippets.

@lastland
Created April 6, 2012 15:25
Show Gist options
  • Save lastland/2320761 to your computer and use it in GitHub Desktop.
Save lastland/2320761 to your computer and use it in GitHub Desktop.
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