Part III: Convert from a natural hexaicosadecimal number to a double
Your next step is to convert a "natural” (that is, whole and zero or positive) hexaicosadecimal number to its equivalent decimal representation. (Where should this code go? Hint: You shouldn't create any more methods than you already have.) We'll start with just natural numbers for now to keep things simple, but eventually we'll be dealing with hexaicosadecimal numbers that are floating point – like floating.point - and/or negative – like-negative.
The algorithm for doing this might look something like:
accumulator = 0 for each character in the input String from left to right
baseValue = the integer equivalent of the current character
accumulator += baseValue * 26 length of the whole String –(index of the current character + 1)
return accumulator
This is relatively straightforward using appropriate methods from the String class and the Math class, but computing "the integer equivalent of a character" can be a little bit tricky if you've never seen it before.
One thing to note is that characters in Java use the Unicode standard, which in turn contains the ASCII standard (a table of ASCII characters can be found here:
https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html)
Another thing to note is that characters in Java are equivalent to their character code. (That is, char c = 'a'; is exactly the same as char c = 97.)
A third thing to note is that the characters in ASCII are arranged in order. (That is, a = 97, b = 98, C = 99...Z = 122).
A fourth thing to note is that while 'a' (97) and 'A' (65) have different character codes, you already know a convenient function that can ensure that your hexaicosadecimal string is all lowercase (or all uppercase, if you prefer), regardless of how it was typed in.
If you take all these points together, you should be able to extract a single character from the
input string and convert it to its equivalent hexaicosadecimal value (That is, a/A = 0, b/B = 1, c/C = 2, ... Z/Z = 25) simply. (By “simply" I mean one or two short lines of code; if you find yourself wanting to use more than this, perhaps go back to the drawing board.)
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.