Re: How does one convert from string to integer using an arbitrary radix?

2018-10-22 Thread mratsim
You can use this bigint implementation as reference: [https://github.com/status-im/nim-stint/blob/4fe901d33b9f5b3ad5f51a587bf6bbb6eb20121b/stint/io.nim#L135-L154](https://github.com/status-im/nim-stint/blob/4fe901d33b9f5b3ad5f51a587bf6bbb6eb20121b/stint/io.nim#L135-L154)

Re: How does one convert from string to integer using an arbitrary radix?

2018-10-21 Thread vsajip
Great, thanks.

Re: How does one convert from string to integer using an arbitrary radix?

2018-10-21 Thread lscrd
The message is misleading. "result" is the one at line 325 in system.nim, i.e. the HSlice which is returned by the proc. When instanciating the slice (".."), the fields "a" and "b" of "result" (a slice) should be initialized with 0. But "b" is of type "range[8..10] and cannot be initialized wit

Re: How does one convert from string to integer using an arbitrary radix?

2018-10-21 Thread vsajip
Thanks for the pointer. I adapted the example like this: const DIGITS = "0123456789" proc parseInt(s : string, radix: range[8..10]) : uint64 = var str = s result = 0 for i in 0 .. str.high: let c = str[i] assert c in DIGITS[0 ..< radi

Re: How does one convert from string to integer using an arbitrary radix?

2018-10-21 Thread Hlaaftana
Not in the standard library. Example implementation here [https://rosettacode.org/wiki/Non-decimal_radices/Convert#Nim](https://rosettacode.org/wiki/Non-decimal_radices/Convert#Nim)

How does one convert from string to integer using an arbitrary radix?

2018-10-20 Thread vsajip
I see the parseutils module has parseHex, parseOct and parseInt and the dom module exposes a C function parseInt that converts a C string to a number with an arbitrary radix, but I don't see a parseInt(s: string, radix: int): int in the documentation. Have I missed it, or is this functionality i