logoalt Hacker News

dlcarrieryesterday at 6:36 PM1 replyview on HN

Here's a readability tip for working with ASCII numbers: Treat adding and subtracting the ASCIIness as you would multiplying and dividing by a unit in physics. You can add '0' to convert a numeral to ASCII and subtract '0' to convert it back, and you can do direct comparisons between ASCII numerals.

    if(characters[i] <= '9' && characters[i] >= '0')
    {
      ret = ret * 10 + characters[i] - '0';
    }

Replies