(int) expression must start with a digit?

Started by m35, June 05, 2009, 10:33:37 AM

Previous topic - Next topic

m35

I see in the manual these examples for the (int) function.
(int "1111" 0 2)  → 15   ; base 2 conversion
(int "0FF" 0 16)  → 255  ; base 16 conversion

Trying some of my own variations:
> (int "ff")
nil
> (int "0xff")
255
> (int "0ff")
0
> (int "ff" 'err 16)
err
> (int "0xff" 'err 16)
255
> (int "0ff" 'err 16)
255
> (int "-0ff" 'err 16)
-255
> (int "-ff" 'err 16)
err
> (int "-ff" 'err 16)


So it seems the expression must always start with a digit.



I'm trying to parse a lot of hex values that look like "ffff" or "-ffff".



I suppose I can append a 0 or 0x in front of the expression if it's positive, or insert a 0 or 0x after the '-' if it's negative, but this seems like an annoyance.



If the base is supplied, couldn't it work even if there is no leading digit?

Lutz

#1
They will all work without the leading zero in version 10.0.8


> (int "ff" 'err 16)
255
> (int "-ff" 'err 16)
-255
> (int "+ff" 'err 16)
255
>

m35

#2
Cool, thank Lutz :D