I am an old assembly programmer and I am trying to teach myself c programming.
I have a function that converts a 32 bit value for endianess and I can't figure out why I do not the the corrected value returned.
This is part of my code
Code:
int process_cmd(int sock)
{
int cmd, ccmd, res;
int (* process_func)(int);
RECV_INTEGER(&cmd);
ccmd=cmd;
BYTESWAP2(ccmd);
printf("converted %08X\n", ccmd);
This is my function
Code:
int BYTESWAP2(ccmd)
{
return (((ccmd&0x000000FF)<<24)+((ccmd&0x0000FF00)<<8)+
((ccmd&0x00FF0000)>>8)+((ccmd&0xFF000000)>>24));
}
The function input is 0158DA00 and should return 00DA5801 and yet it
after the function ccmd = 0158DA00
What am I doing wrong ?