Integer to hexadecimal string

BCS ao at pathlink.com
Wed Jul 9 09:24:35 PDT 2008


Reply to Jarrett,

> "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.
> 

I think that won't work. The only place I know that .stringof works that 
way is __LINE__.stringof but that's special cased in the lexer IIRC.




More information about the Digitalmars-d-learn mailing list