Integer (representing a sequence of bits) reinterpretation as Character Array in Python
<p>I've written some C code that I would like to port to python, as I feel python is a better 'concept' language.</p>

<p>In my C code, I use memory reinterpretation to achieve my goals, for example:</p>

<pre><code>sizeof(int)  is 4 byte
sizeof(char) is 1 byte

char c[4]={0x01,0x30,0x00,0x80};
int* i=(int*)c;

*i has the value 0x80003001
</code></pre>

<p>similarly if i have:</p>

<pre><code>int* j = (int*)malloc(sizeof(int));
char* c = (char*)j;
*j = 0x78FF00AA;

c is now {0xAA, 0x00, 0xFF, 0x78}
</code></pre>

<p>I would like to do a similar thing in python, I realise that I can use bit operations to accomplish this:</p>

<pre><code>chararray=[]
num=1234567890
size=8

while len(chararray) &lt; size:
   char = chr( (num &amp; 255 ) )
   num = num &gt;&gt; 8
   chararray.append(char)
</code></pre>

<p>However I was hoping there would be a faster way of accomplishing this.</p>

<p>Does python have anything similar to C's union?</p>
