short int and
long int from a byte character on C can make
you shoot your feet sometimes. Especially if you’re coding it in
Little Endian machine and processing them on Big Endian machine.
Suddenly you get a different result. For example take a look at this code
This code when processed in Big Endian machine can correctly translate a byte character to Long and Short. What it did is it assume that the Most Significant Bit is stored on the lowest address. but if we run this code on the Little Endian machine (such as your ordinary Intel machine) it will produce a different result because on Little Endian the Least Significant Bit is stored in the lowest address, and that can cause a bug in you application. To fix things lets change the code to the following
This code is better because it doesn’t assume that MSB is stored in the lowest address, it just bit shifting and ‘OR’ing memory address value.