Casting integer to character
The most general approach for extracting pieces of an integer value is to shift and mask. So:

d = whatever;
c = d &amp; 0xff; // extract low 8 bits
c = (d &gt;&gt; 8) &amp; 0xff; // extract next 8 bits


If, as here, you know that the value in d is 16 bits, you can make the code for the next 8 bits a little simpler by writing

c = d &gt;&gt; 8; // extract high 8 bits of 16-bit value