title: Converting 32-bit integer into array of four 8-bit integers in Python
body: <p>How to efficiently convert a 32-bit integer into an array of four 8-bit integers in Python? </p>
  
  <p>Currently I have the following code, which is super slow: </p>
  
  <pre><code>def convert(int32_val):
      bin = np.binary_repr(int32_val, width = 32) 
      int8_arr = [int(bin[0:8],2), int(bin[8:16],2), 
                  int(bin[16:24],2), int(bin[24:32],2)]
      return int8_arr  
  </code></pre>
  
  <p>E.g:</p>
  
  <pre><code>print convert(1)
  &gt;&gt;&gt; [0, 0, 0, 1]   
  
  print convert(-1)
  &gt;&gt;&gt; [255, 255, 255, 255]
  
  print convert(-1306918380)  
  &gt;&gt;&gt; [178, 26, 2, 20]
  </code></pre>
  
  <p>I need to achieve the same behavior on unsigned 32-bit integers. </p>
  
  <p>Additionally. Is it possible to vectorize it for a large numpy array of 32bit integers?</p>