'Why is there an unnecessary or operation when inverting bytes?

I am really confused by this, however trivial it may be. Here's an example (which I tried on paper):

uint16_t val               = 32;                      //00000000 00100000
uint16_t swapped           = val >> 8;                //00100000 00000000
uint16_t swapped2          = val << 8;                //00100000 00000000
uint16_t swapped3          = (val >> 8) | (val << 8); //00100000 00000000

I may be missing something... But as far as I know, they all have the same value, I was wondering maybe the operation in "swapped3" was a safeguard/good practice when doing the same for unsigned 32 bit values, but it wouldn't make sense.

I've tried to search answers online, but all operations are either this or a play on it.

Enlighten me, if possible, binary operations make my head spin.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source