Hacker News new | ask | show | jobs
by dlcarrier 27 days ago
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';
    }
1 comments

I was trying to remember how to do that, I forgot you can subtract '0', and was thinking that - 0 obviously wouldn't work