Hello,
I am trying to perform an endian swap using the union method:
Code:
#include <pthread.h>
#include <stdio.h>

typedef union
{
    char c[sizeof(int)];
    int i;
} buff;

int endianSwap(int i)
{
    buff eswap;
    eswap.i = i;

    eswap.c[0] = (8>>eswap.c[0] | eswap.c[0]<<8 );
    eswap.c[1] = (8>>eswap.c[1] | eswap.c[1]<<8 );
    eswap.c[2] = (8>>eswap.c[2] | eswap.c[2]<<8 );
    eswap.c[3] = (8>>eswap.c[3] | eswap.c[3]<<8 );

    return eswap.i;
}

int main(void)
{
    int i = 1;
    printf("%d is i\n",  i);
    i = endianSwap(i);


    printf("%d  is i\n", i);
    return 0;
}
If I use "1" as a parameter it does not makes the ingeger that must have the rightmost bit set to 1 gives a different value? What is wrong here? I was trying to manipulate byte by byte using the union addressing. Maybe a misstake?