title: convert Integers to RGB values and back with Python
body: <p>I have two functions, one to return RGB values from a given Integer, and the other function does the reverse, providing it with RGB values it returns an Integer. I'm testing this by seeing if the integer i convert to RGB turns back from RGB into the original integer value, but I'm getting different values. </p>
  
  <pre><code>def getRGBfromI(RGBint):
      blue =  RGBint &amp; 255
      green = (RGBint &gt;&gt; 8) &amp; 255
      red =   (RGBint &gt;&gt; 16) &amp; 255
      return red, green, blue
  
  def getIfromRGB(rgb):
      red = rgb[0]
      green = rgb[1]
      blue = rgb[2]
      print red, green, blue
      RGBint = (red&lt;&lt;16) + (green&lt;&lt;8) + blue
      return RGBint
  </code></pre>
  
  <p>the test:</p>
  
  <pre><code>i1 = 2147483647
  colr1 = getRGBfromI(i1)
  print colr1 # returns (255,255,255)
  
  i2 =getIfromRGB(colr1)
  
  print i1, i2 # returns 2147483647 16777215
  </code></pre>
  
  <p>To me it seems like the getRGBfromI() is correct and the getIfromRGB() is incorrect, but I may be wrong about that too. </p>