+91 9945200008     support@uttaracomputers.com
LOGIN     REGISTER    

DOUBT IN AUDIO-10 (OPERATORS I-6)

0
0

When i do casting from long to short will it consider LSB or MSB?

  • You must to post comments
0
0

When casting from a higher data type to a lower type, the basic principle is to make sure that the value is correct, if at all it can be correct.  If it cannot be correct, the C compiler does not care how much wrong it is.

Since this cast will be correct only if the higher data type value is withing the range of the lower type, casting always implies retaining the Lower Significant Part ( and NOT the More Significant Part ).  Hence the C compiler chops of higher bits in the casting.

long –> short   :   Chops off the MS 16 bits and retains the LS 16 bits.

long –> char    :   Chops off the MS 24 bits and retains the Least Significant 8 bits.

 

MLS Shastry

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.