Map integers, shorts and char to bitpattern
<p>Imagine that I have the following variables:</p>

<pre><code>unsigned long a = 1;    //32-bit value
unsigned short b = 1;   //16-bit value
unsigned char c ='\x01' //8-bit value

unsigned char buffer[7];
</code></pre>

<p>Now I would like to map or combine those variables above in the buffer as follows:
first four bytes should be occupied by value of int a, next 2 bytes by value b and the last byte by c.</p>

<pre><code>==&gt; buffer = 0x 00000001 0001 01
</code></pre>

<p>Is here anyone aware of an easy way to do that in C++? At the moment I am having help function that return the byte pattern for shorts and integers but I guess in C++ there must be a better way to do that?</p>

<p>Thanks</p>
