I'm assuming you are using C, not C++:
logical method
Code:
u_short a = 0x4567;
u_char b[sizeof(u_short)], *pB = b;
while (pB < b+sizeof(u_short))
{
*pB++ = a&0xFF;
a >>= 8;
}
// gives array b[]
union method
Code:
u_short a = 0x4567;
union
{
u_short a1;
u_char b[sizeof(u_short)];
} both;
both.a1 = a;
// gives array both.b[]
casting method
Code:
u_short a = 0x4567;
u_char *b = (u_char *) &a;
// gives array b[]
Caveats:
1. watch out for byte order issues (some architectures have high byte first), which affect the second two methods
2. the size of a u_short is not necessarily the same between different architectures or compilers
The first method is not as cpu time expensive as it looks, and the semantics are better defined.