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

  • Home
  • SEARCH
  • 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 360363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:28:55+00:00 2026-05-12T12:28:55+00:00

Was asked this question recently and did not know the answer. From a high

  • 0

Was asked this question recently and did not know the answer. From a high level can someone explain how Java takes a character / String and convert it into an int.

  • 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-12T12:28:55+00:00Added an answer on May 12, 2026 at 12:28 pm

    Usually this is done like this:

    • init result with 0
    • for each character in string do this
      • result = result * 10
      • get the digit from the character (‘0’ is 48 ASCII (or 0x30), so just subtract that from the character ASCII code to get the digit)
      • add the digit to the result
    • return result

    Edit: This works for any base if you replace 10 with the correct base and adjust the obtaining of the digit from the corresponding character (should work as is for bases lower than 10, but would need a little adjusting for higher bases – like hexadecimal – since letters are separated from numbers by 7 characters).

    Edit 2: Char to digit value conversion: characters ‘0’ to ‘9’ have ASCII values 48 to 57 (0x30 to 0x39 in hexa), so in order to convert a character to its digit value a simple subtraction is needed. Usually it’s done like this (where ord is the function that gives the ASCII code of the character):

    digit = ord(char) - ord('0')
    

    For higher number bases the letters are used as ‘digits’ (A-F in hexa), but letters start from 65 (0x41 hexa) which means there’s a gap that we have to account for:

    digit = ord(char) - ord('0')
    if digit > 9 then digit -= 7
    

    Example: ‘B’ is 66, so ord(‘B’) – ord(‘0’) = 18. Since 18 is larger than 9 we subtract 7 and the end result will be 11 – the value of the ‘digit’ B.

    One more thing to note here – this works only for uppercase letters, so the number must be first converted to uppercase.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 225k
  • Answers 225k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is a very basic screen scraping way to achieve… May 13, 2026 at 12:56 am
  • Editorial Team
    Editorial Team added an answer In parent expect the refreshed values something like as: parent.php?value=xxx… May 13, 2026 at 12:56 am
  • Editorial Team
    Editorial Team added an answer It depends what you are trying to add to the… May 13, 2026 at 12:56 am

Related Questions

How does the system know what to use when 'this' keyword is used? Recently,
This is mostly a rhetorical question, as far as I've checked the answer is
One of my colleagues recently interviewed some candidates for a job and one said
Recently in an interview I was asked several questions related to the Big-O of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.