i have got an 32bit (hexadecimal)word 0xaabbccdd and have to swap the 2. and the 3. byte. in the end it should look like 0xaaccbbdd
how can i \"mask\" the 2nd and the 3r
You vould just use pointers to swap two bytes
static union { BYTE BBuf[4]; WORD WWBuf[2]; DWORD DWBuf; }swap; unsigned char *a; unsigned char *b; swap.DWBuf = 0xaabbccdd; a = &swap.BBuf[1]; b = &swap.BBuf[2]; *a ^= *b; *b ^= *a; *a ^= *b;
And now the result is
swap.DWbuf == 0xaaccbbdd;