(int) expression must start with a digit?

Q&A's, tips, howto's
Locked
m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm

(int) expression must start with a digit?

Post by m35 »

I see in the manual these examples for the (int) function.

Code: Select all

(int "1111" 0 2)  → 15   ; base 2 conversion
(int "0FF" 0 16)  → 255  ; base 16 conversion
Trying some of my own variations:

Code: Select all

> (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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

They will all work without the leading zero in version 10.0.8

Code: Select all

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

m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm

Post by m35 »

Cool, thank Lutz :D

Locked