Split 16-bit Data into two 8 bit data in C/C++

There are two way to achieve the output, using
1. Union
2. Shift Operator

The Functionally of the union is to share the data. So using the union can split the data. For that you need to create structure with in union. For Example,

union MyData
{
unsigned short nData ;
struct
{
unsigned char nDataLSB ;
unsigned char nDataMSB ;
} SplitData ;
} ;

Another way is to use the shift operator (Left shift or right shift). For Example

unsigned short nData = 10 ;

unsigned char nDataMSB = nData >> 8 ;
unsigned char nDataLSB = nData ;

These two is not the only way to split the data. The specified two method is very simple and easy to use.