Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

single digit decimal to 2 digit hex

Status
Not open for further replies.

OieL

MIS
Sep 6, 2002
17
0
0
US

how can i convert a single digit decimal to hex value but with a 0 preceeding it ..

ie

printf "%X%X%X", 0,1,2 ;

will output 012

how can i make it ouput like "000102" im doing this to convert RGB color values to hex (html color chart).





 
Well, I suspect that your actual print statement looks different that the one you posted, but if you stuff your RGB values into an array you can format it using
Code:
@rgb = (0, 1, 2);
printf "0"x(6-@rgb)."%X"x@rgb, @rgb;

jaa
 
This works:

printf "%02x%02x%02x\n", 0,1,2;

HTH. Hardy Merrill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top