Created: 2021-12-08T20:09:08-06:00
This card pertains to a resource available on the internet.
XORing byte pairs 3 times swaps their endian in-place
int swap_endian(int x) { char *c; c = (char *)&x; /* XOR byte pairs 3 times swaps them in place */ c[0]=c[0]^c[3]; c[3]=c[0]^c[3]; c[0]=c[0]^c[3]; c[1]=c[1]^c[2]; c[2]=c[1]^c[2]; c[1]=c[1]^c[2]; return(x); }