-- Leo's gemini proxy

-- Connecting to iceworks.cc:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

"Big Endian" and "Little Endian" Formats for Integers

Created: 2021-12-08T20:09:08-06:00

Return to the Index

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);
}

-- Response ended

-- Page fetched on Thu May 23 19:00:41 2024