title: Why is my rgb to uint32 preprocessor macro giving me a wrong colorcode?
body: <p>I am learning about bit wise operators and ran into this problem:</p>
  <blockquote>
  <p>In computer graphics, colors are often stores as three numbers,
  representing red, green and blue intensities. Suppose that each number requires eight bits, and we'd like to store all three values in a single long integer.</p>
  <p>Write a macro named <code>MK_COLOR</code> with three parameters (the red, green and blue intensities). <code>MK_COLOR</code> should return a <code>long</code> in which
  the last three bytes contain the red, green and blue intensities, with the red value as the last byte and the green value as the next-to-last byte.</p>
  </blockquote>
  <p>The solution is:</p>
  <pre class="lang-c prettyprint-override"><code>#define MK_COLOR(r,g,b) ((long) (b) &lt;&lt; 16 | (g) &lt;&lt; 8 | (r))
  </code></pre>
  <p>I don't fully understand how the solution works, so I will try to break down my understanding, lets say <code>r = 20</code> (10100), <code>g = 30</code> (11110) and <code>b = 40</code> (101000).</p>
  <ol>
  <li><code>b</code> is shifted left by 16 bits so we get <code>00010100 00000000 00000000</code></li>
  <li><code>g</code> is shifted by 8 bits so we get <code>11110000</code></li>
  <li>there is a <code>|</code> OR operator which looks like this:</li>
  </ol>
  <pre class="lang-none prettyprint-override"><code>  00010100 00000000 00000000 
  | 11110000 00000000 00000000
   ---------------------------
    11110100 00000000 00000000 
  </code></pre>
  <ol start="4">
  <li>the last step does OR on this result we got but with <code>r</code> which looks like this:</li>
  </ol>
  <pre class="lang-none prettyprint-override"><code>  11110100 00000000 00000000 
  | 10100000 00000000 00000000
   ---------------------------
    11110100 00000000 00000000 // result
  </code></pre>
  <p>The result is <code>11110100 00000000 00000000</code> which is <code>15990784</code> in decimal. This result however is incorrect according to when I run the program and get <code>2629140</code> as the answer.</p>
  <p>Why is it wrong? Could you please explain what I did wrong and how I can better my understanding of this?</p>