A function to handle multiple datatypes

michael_x:
Or do you want to "turn around" every single byte bit by bit

Ignore the whole thing about MSB first. It isn't relevant. My mistake.

Honestly, this is why you shouldn't fiddle with pointers if you don't understand what you are doing.

Whilst I will happily admit that my knowledge of pointers is far from encyclopaedic the code to which you refer is a simple bit wise XOR operation.
The whole point of the bit stuffing is to allow me to use a customised data packet for transmission over the serial port. The packet uses the value 0x7E to signify the start and the finish of the packet. However, this means that if the packet payload data contains the value 0x7E then we have to modify it so that the receiver does not think it had reached the end of the packet, thereby causing data loss. So what we do is to replace 0x7E with 0x7D and then follow it with the original value XOR'd with 0x20 giving 0x5E. We also follow any other occurrence of 0x7D with 0x7D XOR'd with 0x20.
Upon receiving the packet any occurrence of 0x7D is discarded and the following byte XOR'd with 0x20 to obtain the original value, thereby "unstuffing" the bytes.
Honestly, this is why you shouldn't fiddle with bitwise operations if you don't understand what you're doing. :wink: