In the following code I need to print the color in Hex format.
First Print statement is showing value in RGB format
I know this is rather old, but you can get a simpler solution by using org.openqa.selenium.support.Color:
import org.openqa.selenium.support.Color;
String color = driver.findElement(By.xpath("//div[@class='gb_e gb_f gb_g gb_xb']/a")).getCssValue("color");
System.out.println(color);
String hex = Color.fromString(color).asHex();
System.out.println(hex);
It gives you a single line solution and even adds leading zeroes when required (something that the previous answers aren't accounting for)