- Subject: Re: [slang-users] integer() returns unexpected values
- From: "John E. Davis" <davis@xxxxxxxxxxxxx>
- Date: Mon, 18 Feb 2013 10:58:01 -0500
Remko van der Vossen <wich@xxxxxxxxx> wrote:
> On Sat, Feb 16, 2013 at 10:29:15PM -0600, J.B. Nicholson-Owens wrote:
>> I did not expect integer() to do the following:
>>
>> slsh> integer("023");
>> 19
>
> It is pretty common to interpret integers with a leading zero as octal,
> which is indeed what happens in this case.
> I don't know the exact specs of integer, but I would not be surprised if
> it also supports 0x12ab notation for hexadecimal and perhaps also 1010b
> for binary.
Yes, that is correct. For decimal integers, the `atoi` function can
be used:
slsh> atoi("023");
23
integer("0b10111");
23
I see that I need to update the docs to suggest atoi as an alternative.
Thanks,
--John
[2013 date index]
[2013 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]