Char array to long to char array
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6370894/converting-a-four-character-string-to-a-long">Converting a four character string to a long</a>  </p>
</blockquote>



<p>I want to convert a char array to a long and back again but I'm a bit stuck.</p>

<p>This is a fragment of the code I've got so far:</p>

<pre><code>char mychararray[4] = {'a', 'b', 'c', 'd'};
unsigned long * mylong = (unsigned long *)&amp;mychararray;
cout &lt;&lt; *mylong &lt;&lt; endl;
</code></pre>

<p>Which should take the char array, and represent the first 4 bytes (the length of a long) as a long (I think).</p>

<p>Is this correct? And how would I undo it to get the char array back?</p>

<p>Thanks for your help.</p>

<p>EDIT: The third line was a typo - *mychararray should have been *mylong</p>
