Number 4 represented as a 32-bit unsigned integer would be
on a big endian machine: 00000000 00000000 00000000 00000100 (most significant byte first)
on a small endian machine: 00000100 00000000 00000000 00000000 (most significant byte last)
As a 8-bit unsigned integer it is represented as 00000100 on both machines.
Now when casting 8-bit uint to a 32-bit I always thought that on a big endian machine that means sticking 24 zeros in front of the existing byte, and appending 24 zeros to the end if the machine is little endian. However, someone pointed out that in both cases zeros are prepended rather than appended. But wouldn't it mean that on a little endian 00000100 will become the most significant byte, which will result in a very large number? Please explain where I am wrong.
(uint32_t)myByteis the same as the value ofmyByte. - Oliver Charlesworth