title: Calculating opacity value mathematically
body: <p>How is opacity calculated mathematically?</p>
  
  <p>There is opacity value in Photoshop, CSS etc. Actually this opacity is the transparent behavior of a layer. That we all know.
  But how is it calculated mathematically? Is there any equation to calculate opacity?</p>
  
  <p>By setting opacity value what is happening there?</p>
  
  <p>Take the case of plain color layers: Layer 1 (Foreground Layer) and Layer 2 (background layer)</p>
  
  <p>Layer 1 is red (say color value <code>A</code>) and Layer 2 is white (say color value <code>B</code>). </p>
  
  <p>When we set opacity (say <code>p</code>) to layer 1, we can put 0.5 or 50% and get a whitish red color (say color value <code>X</code>).</p>
  
  <p>For getting this value <code>X</code> what should I do mathematically?</p>
  
  <p>ie.</p>
  
  <pre><code>X = (things which will be a relation containing p, A and B)
  </code></pre>
  
  <p>I want to know the exact mathematical equation to find <code>X</code>.</p>
  
  <p>Also if I have the equation, and color values are hexadecimal in nature, so with a hex calculator can I get a correct result?</p>