read Hexadecimal value from string

David L. Davis SpottedTiger at
Tue Jul 17 14:03:51 PDT 2007

Frank Benoit Wrote:

> When using Tango, this can be done like this:
> import tango.text.convert.Integer;
> int  i = toInt( "12AB", 16 );
> long l = toLong( "ffffFFFFAAAA", 16 );
> see also:
> and the source at
> Frank

Yep, Tango has some very kool functions. But I do want to point out that Phobos does have a radix parameter in the toString functions for converting a number to a string...sadly not the other way around.

Here's an example:
// Using Phobos you can convert a long or a ulong value, 
// using any base from 2 to 36 into a string
private import ss = std.string;
private import io = std.stdio;

void main()
    auto s = ss.toString(12uL, 16u);
    io.writefln("ss.toString(12uL, 16u)=\"%s\"", s);

/+ Output:
C:\dmd>dmd strex1.d
C:\dmd\bin\..\..\dm\bin\link.exe strex1,,,user32+kernel32/noi;

ss.toString(12uL, 16u)="C"


David L. Davis

More information about the Digitalmars-d-learn mailing list