• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 722
  • Last Modified:

pseudocode for ascii to integer

This is sort of a general question, but something that might come up in a job interview.  If someone asked you to write an ascii to integer function in pseudocode for them, how would you go about doing it?
0
texasreddog
Asked:
texasreddog
1 Solution
 
ozoCommented:
You do not specify what kind of maping from ascii to integer you want
something as simple as
integer = ascii;
would get an integer  in many languages.
You may want  ord(substr(string,0,1)) at another level of abstraction
If you want to convert an ascii string representation of a decimal numnber, it might be something like
integer=0;
for character in string do
  integer = 10 * integer + ord(character)-ord('0')
end
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now