What does stripping off the ASCII template mean?

前端 未结 1 1531
予麋鹿
予麋鹿 2021-01-24 23:34

I am working on a practice exam problem

The Problem On execution of this program, the user inputs two numbers. What is the value of xGuess so we can st

相关标签:
1条回答
  • 2021-01-25 00:27

    As you noticed, operations are performed on ASCII values of entered characters. In assembly, if you read characters from keyboard, you really get their ASCII values in registers, so let's say you enter 2 and 3 and want to add them, then you are really adding 50+51. You have to subtract 48 first, from each entered character, because 48 is a value of 0 character in ASCII. I think this is called "stripping off the ASCII template". Then, if you want to display the result of calculation on the screen, you have to add 48 back to the result (only if entered character and the result is single digit, for bigger numbers it involves more operations). Howerer, this makes sense for characters 0-9. I don't know why would you want to make calculations on alphabet characters, like a and b in your example.

    0 讨论(0)
提交回复
热议问题