Thread overview | ||||||
---|---|---|---|---|---|---|
|
August 03, 2011 Hexadecimal string to integer | ||||
---|---|---|---|---|
| ||||
std.conv does not support conversion from a hexadecimal string to an integer. Is there a technical reason for this limitation? This is the best I could do, can it be improved still? int i = to!int(parse!float("0x1ap0")); |
August 03, 2011 Re: Hexadecimal string to integer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stijn Herreman | On 8/2/2011 8:17 PM, Stijn Herreman wrote:
> std.conv does not support conversion from a hexadecimal string to an
> integer. Is there a technical reason for this limitation?
>
> This is the best I could do, can it be improved still?
> int i = to!int(parse!float("0x1ap0"));
parse!int("1a", 16);
|
August 03, 2011 Re: Hexadecimal string to integer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johann MacDonagh | On 3/08/2011 2:32, Johann MacDonagh wrote:
> On 8/2/2011 8:17 PM, Stijn Herreman wrote:
>> std.conv does not support conversion from a hexadecimal string to an
>> integer. Is there a technical reason for this limitation?
>>
>> This is the best I could do, can it be improved still?
>> int i = to!int(parse!float("0x1ap0"));
>
> parse!int("1a", 16);
I tried multiple combinations but not that one, thanks.
|
August 04, 2011 Re: Hexadecimal string to integer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stijn Herreman | On 08/03/2011 10:44 AM, Stijn Herreman wrote: > On 3/08/2011 2:32, Johann MacDonagh wrote: >> On 8/2/2011 8:17 PM, Stijn Herreman wrote: >>> std.conv does not support conversion from a hexadecimal string to an >>> integer. Is there a technical reason for this limitation? >>> >>> This is the best I could do, can it be improved still? >>> int i = to!int(parse!float("0x1ap0")); >> >> parse!int("1a", 16); > I tried multiple combinations but not that one, thanks. I am doing: to!(int)(BigInt("0x1a").toInt()); toInt actually returns a long: http://www.d-programming-language.org/phobos/std_bigint.html It's kinda frustrating, but it's there. |
Copyright © 1999-2021 by the D Language Foundation