Skip to content

Instantly share code, notes, and snippets.

@lastland
Created April 6, 2012 15:25

Revisions

  1. lastland created this gist Apr 6, 2012.
    16 changes: 16 additions & 0 deletions FloatSwap.cc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #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;
    }