Convert RGB value to Hexadecimal (to be used in HTML for example)

From CodeCodex

Revision as of 08:03, 18 August 2009 by Techmind (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Implementations

Java

<highlightsyntax language="java122"> import java.awt.*; public class Color2Hex {

 public static void main( String[] args ) {
   if (args.length != 3) {
     System.out.println("Color2Hex  r g b");
     }
  else {
     int i = Integer.parseInt(args[0]);
     int j = Integer.parseInt(args[1]);
     int k = Integer.parseInt(args[2]);
   
     Color c = new Color(i,j,k);
     System.out.println
       ( "hex: " + Integer.toHexString( c.getRGB() & 0x00ffffff ) ); 
     }
  }

} </highlightsyntax>