1.
((longInt >> 24) & 0xFF) expression is of type unsigned long int . When converting to int expression is first converted to int , then to unsigned char . If you have not added to int , the expression will not be converted to int at first. There is no difference in the two situations, and casting is redundant.
2.
0xff not required. Converting to unsigned char actually does the same.
3.
You can use memcpy , but it is not portable, because it depends on the content capacity of the system. This will give different results if the system is a large entica or a small value, while solving the bitwise shift will give the same results.
source share