Integer to hexadecimal string
    Jarrett Billingsley 
    kb3ctd2 at yahoo.com
       
    Tue Jul  8 20:30:06 PDT 2008
    
    
  
"BCS" <ao at pathlink.com> wrote in message 
news:55391cb32eed78caaf3194222520 at news.digitalmars.com...
> you can even force the format string to be built at compile time.
>
> char[] toHex(T)(T arg){ return format("%."~itoa!(T.sizeof * 2)~"x", 
> arg); }
No function necessary.
return format("%." ~ (T.sizeof * 2).stringof ~ "x", arg);
Untested, but you can use .stringof to do number to string at compile time. 
Not sure if it'll give "T.sizeof * 2" instead here :P  might have to put it 
in a const. 
    
    
More information about the Digitalmars-d-learn
mailing list