title: c/c++ how to convert short to char
body: <p>I am using ms c++. I am using struct like </p>
  
  <pre><code>    struct header   {
          unsigned port : 16;
                  unsigned destport : 16;
          unsigned not_used : 7;
          unsigned packet_length : 9;
  
  
      };
  struct header HR;
  </code></pre>
  
  <p>here this value of header i need to put in separate char array.</p>
  
  <p>i did  <code>memcpy(&amp;REQUEST[0], &amp;HR, sizeof(HR));</code>  </p>
  
  <p>but value of packet_length is not appearing properly.</p>
  
  <p>like if i am assigning HR.packet_length = 31; 
  i am getting -128(at fifth byte) and 15(at sixth byte).</p>
  
  <p>if you can help me with this or if their is more elegant way to do this.</p>
  
  <p>thanks</p>