Bytes from integer using bitwise operators
Contrary to what you think, extracing bytes by shifting and masking is completely unrelated to the storage order (both little-endian and big-endian storage schemes exist and don't influence the results).

An int variable is represented by 32 bits. The least significant byte is made of the eight least significant bits and you obtain them by

i &amp; 0xFF
0b 111111111 0101010 01010101 000000000 =&gt; 0b 00000000 00000000 00000000 00000000 


The neighboring byte is made of the eight neighboring bits; you discard the eight least significant bits by shifting (>>), then mask out:

(i &gt;&gt; 8) &amp; 0xFF
0b 11111111 10101010 01010101 000000000 =&gt; 0b 00000000 00000000 00000000 01010101 


And similarly for the remaining two bytes, with shifts of 16 and 24 (most significant byte).

Notice that I cared not to use the terms left/right and first/last, which are meaningless as they refer to some graphical representation or memory storage order. In the examples, the numbers are understood as binary numbers written with lsb on the right (and spacers for clarity), which is the most common convention.