Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6335593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:53:18+00:00 2026-05-24T18:53:18+00:00

Many languages have functions for converting string to integer and vice versa. So what

  • 0

Many languages have functions for converting string to integer and vice versa. So what happens there? What algorithm is being executed during conversion?

I don’t ask in specific language because I think it should be similar in all of them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:53:19+00:00Added an answer on May 24, 2026 at 6:53 pm

    To convert a string to an integer, take each character in turn and if it’s in the range ‘0’ through ‘9’, convert it to its decimal equivalent. Usually that’s simply subtracting the character value of ‘0’. Now multiply any previous results by 10 and add the new value. Repeat until there are no digits left. If there was a leading ‘-‘ minus sign, invert the result.

    To convert an integer to a string, start by inverting the number if it is negative. Divide the integer by 10 and save the remainder. Convert the remainder to a character by adding the character value of ‘0’. Push this to the beginning of the string; now repeat with the value that you obtained from the division. Repeat until the divided value is zero. Put out a leading ‘-‘ minus sign if the number started out negative.

    Here are concrete implementations in Python, which in my opinion is the language closest to pseudo-code.

    def string_to_int(s):
        i = 0
        sign = 1
        if s[0] == '-':
            sign = -1
            s = s[1:]
        for c in s:
            if not ('0' <= c <= '9'):
                raise ValueError
            i = 10 * i + ord(c) - ord('0')
        return sign * i
    
    def int_to_string(i):
        s = ''
        sign = ''
        if i < 0:
            sign = '-'
            i = -i
        while True:
            remainder = i % 10
            i = i / 10
            s = chr(ord('0') + remainder) + s
            if i == 0:
                break
        return sign + s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There have been many JVM languages in the recent few years including Javascript, Python,
Many languages have functions which only process plaintext, not binary. Does this mean that
Many languages have standard repositories where people donate useful libraries that they want others
Many languages have a facility to check to see if an Object is of
I've often heard the argument (in javascript, but many languages have an eval-like feature)
C++ has std::vector and Java has ArrayList , and many other languages have their
Many languages have an isNaN() function. I am asking myself: why check for not
I'd be interested to know whether there are programming languages which have shorthand equality
I haven't used a statically typed language in many years and have set myself
In many languages, assignments are legal in conditions. I never understood the reason behind

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.