# To encode rgb = red; rgb = (rgb << 8) + green; rgb = (rgb << 8) + blue; # To decode red = (rgb >> 16) & 0xFF; green = (rgb >> 8) & 0xFF; blue = rgb & 0xFF;