why would i subtract from 48 to convert to the character code values
why would i subtract from 48 to convert to the character code values
"Characters" are nothing more than integers. Different integers are used to represent different characters. The ASCII encoding uses 48 to represent '0', 49 to represent '1', ..., 48 + 9 to represent '9'. By subtracting 48, you convert the ASCII character into its integer value.
It's more readable to use (x - '0') than (x - 48), though, and it does not assume you're using the ASCII character set.
It's not only more readable, but safer. There is no guarentee that '0' == 48 (although I have never seen anything else).Originally Posted by Rashakil Fol
but what about atoi to change the character to intergers?
That doesn't change characters. It converts strings, which are series of characters terminated by a null character.
Quzah.
Hope is the first step on the road to disappointment.
EBCDIC stands out as the obvious place where '0' != 48.Originally Posted by Ancient Dragon
http://en.wikipedia.org/wiki/EBCDIC#Codepage_layout
The OP might be interested in http://faq.cprogramming.com/cgi-bin/...&id=1043284385
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]