
`a << b` is undefined when `a` is negative, and `a >> b` is implementation-defined. The correct thing to do here is to cast to unsigned, swap the bytes there and then swap back. This also improves performance on some compilers: Clang is smart enough to recognise that we're byteswapping here and reduce it to a single `bswap` instruction on x86_64, but only for the unsigned versions.