Revised Question -
How to calculate the mask-bits irrespective of the size of integer type? I want to calculate the mask of first 4-bits, when I don't the size of integer.
I have two options to set the MSB 4-bits in the code -
if little_Endian -
then --
int t = 54342;
int k = t<<4;
int t = (k>>4)|0XF000
else big Endian -- then --
int t = 54342;
int k = t>>4;
int t = (k<<4)|0X000F
My question is is there any better way to do so. How can I make the code independent of the endianity? I can use union to determine the endianity. However, I want my code to simple. How can I do so?