Original Post
I've recently been looking into cross platform memory management and was thinking about byte swapping for "endian-ness". My question concerns the "0xff". Why even bother having it? Shouldn't shifting by 8 just push the unwanted bits out of the way anyhow? This seems redundant to me.
typedef unsigned short u16;
u16 endianSwap16(u16 var)
{
u16 left = (((var) & 0xff) << 8);
u16 right = (((var) >> 8) & 0xff);
return left | right;
}