8.1.10 Nibble and Byte Swapping

Next: 8.1.11 Highest Order Bit Up: 8.1 Optimizations Previous: 8.1.9 Bit-rotation Contents Index

## 8.1.10 Nibble and Byte Swapping

Other special cases of the bit-shift operations are nibble or byte swapping, SDCC recognizes the following expressions:

> `unsigned char i;`
> `unsigned int j;`
> `...`
> `i = ((i << 4) | (i >> 4));`
> `j = ((j << 8) | (j >> 8));`

and generates a swap instruction for the nibble swapping or move instructions for the byte swapping. The ''j'' example can be used to convert from little to big-endian or vice versa. If you want to change the endianness of a signed integer you have to cast to `(unsigned int)` first.

Note that SDCC stores numbers in little-endian8.1 format (i.e. lowest order first).