// Convert to int int code = inCode; // Check if it's within the valid color code range if(0<=code && code<=0xffffff){ ...