title: How to convert Hex to RGB?
body: <p>I am trying to use this to figure out if a color is light or dark</p>
  
  <p><a href="https://stackoverflow.com/questions/1754211/evaluate-whether-a-hex-value-is-dark-or-light">Evaluate whether a HEX value is dark or light</a></p>
  
  <p>Now. It takes in a <code>int</code></p>
  
  <pre><code> float calcLuminance(int rgb)
   {
        int r = (rgb &amp; 0xff0000) &gt;&gt; 16;
        int g = (rgb &amp; 0xff00) &gt;&gt; 8;
        int b = (rgb &amp; 0xff);
  
        return (r*0.299f + g*0.587f + b*0.114f) / 256;
   }
  </code></pre>
  
  <p>I have a hex color though.</p>
  
  <p>I tried to do this</p>
  
  <pre><code>  var color = System.Drawing.ColorTranslator.FromHtml("#FFFFFF");
    int rgb = color.R + color.G + color.B;
     var a = calcLuminance(rgb);
  </code></pre>
  
  <p>I got 0.11725 I thought it would have to be in the range of 0-256 or something like that.</p>
  
  <p>What am I doing wrong? Do I have to covert <code>R</code> to an <code>int</code>? Or am I just way off?</p>