# Subtracting an integer from an ASCII number

Theoretically, if I were to subtract the number 10 from the ASCII character 10 (which is really 00110001 00110000), what would I get?

Does the computer add both ASCII characters and subtract?

-
"Theoretically ... ASCII ..." -- that sounds strange to me. Also, it seems that this is an implementation-specific question and might thus be offtopic. Certainly, not every programming language (resp type system) allows you to identify characters and numbers. –  Raphael Feb 2 '13 at 13:20
It's a theoretical/pondering question. I'm wondering how the string 10 minus the number 10 is calculated. –  Imray Feb 3 '13 at 5:21

If you subtract the integer 10 from the ASCII character (code) for 'a' (which is decimal 61) you get the ASCII code for 'Q'.

If you are asking because of mysteriously looking expressions like c - 'a' (or c - '0') (some C hacks are fond of those), they give the letter position of c (respectively the value of the digit c). Used for interesting stuff like c - 'A' + 'a' (uppercase to lowercase), or to translate a decimal ASCII string to integer:

p = string;
s = 0;
for(p = string; *p; p++)
s = 10 * s + *p - '0';

-
'If you subtract the integer 10 from the ASCII character (code) for 'a' (which is decimal 61) you get the ASCII code for 'Q'.' But my question was what do you get if you subtract the int 10 from the ASCII '10'... –  Imray Feb 3 '13 at 5:20
OK, that would be "10" = '1' * 256 + '0' - 10 = '1' * 256 + 38 = '1' * 256 + '&' = "1&" (here I'm writing "10" for the character array {'1', '0'} for compactness). This assumes big-endian shorts, with little-endian it turns out "`0" –  vonbrand Feb 3 '13 at 5:29

It depends how exactly you do the subtraction. Depending on the processor, the string 10 is either 0x3031 (little endian) or 0x3130 (big endian). Most modern processors are little endian. That's assuming you regard 10 as a 16-bit integer, i.e. a C short on modern computers. If you're regarding it as a C char, then only the first digit 1 will be affected.

-