title: How convert unsigned int to unsigned char array
body: <p>I just need to extract those bytes using bitwise &amp; operator. 0xFF is a hexadecimal mask to extract one byte. For 2 bytes, this code is working correctly:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      unsigned int i = 0x7ee;
      unsigned char c[2];
  
      c[0] = i &amp; 0xFF;
      c[1] = (i&gt;&gt;8) &amp; 0xFF;
  
      printf("c[0] = %x \n", c[0]);
      printf("c[1] = %x \n", c[1]);
  
  
      return 0;
  }
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>c[0] = ee;
  c[1] = 7;
  </code></pre>
  
  <p>What should I do for 4 bytes to work correctly?</p>
  
  <pre><code>unsigned int i = 0x557e89f3;
  unsigned char c[4];
  </code></pre>
  
  <p>my code:</p>
  
  <pre><code>unsigned char c[4];
           c[0] = i &amp; 0xFF;
           c[1] = (i&gt;&gt;8) &amp; 0xFF;
           c[2] = (i&gt;&gt;16) &amp; 0xFF;
           c[3] = (i&gt;&gt;24) &amp; 0xFF;
           printf("c[0] = %x \n", c[0]);
           printf("c[1] = %x \n", c[1]);
           printf("c[2] = %x \n", c[2]);
           printf("c[3] = %x \n", c[3]);
  </code></pre>