#include "stdio.h"
#include "math.h"

// swap using char pointers
float swap(float d)
{
    float         a;
    unsigned char *dst = (unsigned char *)&a;
    unsigned char *src = (unsigned char *)&d;

    dst[0] = src[3];
    dst[1] = src[2];
    dst[2] = src[1];
    dst[3] = src[0];

    return a;
}

int main(int argc,char *argv[])
{
    float a;
    float b;
    float c;
    for(a=0.0;a<100.0;a+=0.01) {
        // swap to network byte order
        b = swap(a);
        // swap back
        c = swap(b);
        // now a and C should be EXACTLY the same. but if not, print something
        if (a != c) {
            printf("*****\n%21.18f\n%21.18f\n%21.18f\n%21.18f\n%lx\n%lx\n%lx\n",
            a,b,c,fabs(a-c),*(unsigned long *)&a,*(unsigned long *)&b,*(unsigned long *)&c);
        }


    }
    return 0;
}

