parseInt and hexatridecimals

There’s a bug in ActionScript 2′s parseInt: it strips “0x” or “0X” from the start of the string, regardless of the base. It’s ok in most situations, since “0x” isn’t a valid part of any number base — except 35 and 36. And that’s where the bug lies. If you run parseInt("0XABC", 36) you should get 1553016, but instead you get 13368, which is ABC in base 36.

There’s a very simple workaround (if anyone besides me is actually doing this and using ActionScript 2), and that’s to add “00″ to the start of any base 35 or 36 number passed to parseInt. Why not “0″? you may ask. That would only shift the problem to numbers starting with “X”.

The issue seems to be fixed in ActionScript 3.

Leave a Reply