#I need help understanding how to byteSwap using bitwise operators in C
10 messages · Page 1 of 1 (latest)
looks like it works by swapping the nth and mth bytes
how can i swap them by shifting the nth and mth?
what have you tried?
what would this line do?
int byteSwap(int x, int n, int m) {
int swap = (x>>(n-1) & 0x1) ^ ((x>>(m-1) & 0x1);//extraction of the byte at n and m position based on the value of x
x = x^(swap << (n-1));// first swap places n where m position
x = x^(swap << (m-1));// second swap places m where n position
return x;
0x1 is only going to be extracting a single bit, not a byte
so what if I used like 0xFF