Truncating an int (or long, or whatever) to a specific size (n bytes), signed and unsigned
<p>Say I have these two variables:</p>

<pre><code>size_t value;
size_t size;
</code></pre>

<p>And I want to "cast" <code>value</code> to the size of <code>size</code>.  So if <code>size</code> is 4, <code>value</code> is casted to be 4 bytes long.  If <code>size</code> is 3, <code>value</code> is presumably truncated to 3 bytes long, preserving sign (assume a signed int may be loaded into <code>value</code> then taken out later to be cast back to signed) and stored in an int/uint depending on sign choice.  Preferably with a method that would work to turn, for example, an unsigned long, or whatever other integral type, to any arbitrary size in bytes along with being signed/unsigned.</p>
