Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|cite|improve this question
"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. – CodyBugstein Feb 3 '13 at 5:21
up vote 0 down vote accepted

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';
share|cite|improve this answer
'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'... – CodyBugstein 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.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.