Method 1:

unsigned long l_val;
unsigned short s_low, s_high;
s_low = (unsigned short )l_val;
s_high = (unsigned short )(l_val >> 16);
Method 2:
struct two_short
{
  unsigned short low;
  unsigned short high;
};
unsigned long l_val;
unsigned short s_low, s_high;
struct two_short * p_long;
p_long = (Struct two_short *)&l_val;
s_high = p_long->high;
s_low = p_long->low;
Method 3:
unsigned long l_val;
unsigned short s_low, s_high;
unsigned short * p_short;
p_long = (unsigned short *)&l_val;
s_low = *p_short;
p_short++;
s_high = *p_short;
Please note method 3 only works for only little endian processors.

About our authors: Team EQA

You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.

#