Java String method that I will use in the String <==> Integer conversion algorithm
 

charAt( ):

  • s.charAt(i) = the character at position i in string s

Examples:

   "abc".charAt(0) is 'a' 
   "abc".charAt(1) is 'b' 
   "abc".charAt(2) is 'c' 
   

Finally: a repeated reminder

It's very important that you understand that:

  • The compiler translates every number that you write in a program into its 2s complement (binary) representation

Example:

   When you write:

         x = x * 5;  // 5 is in decimal !!

   The compiler will output instruction codes that
   will tell the CPU to multiply the binary number
   in variable x with the binary number:

          00000000000000000000000000000101 (=5(10)) !

   and store the result back into variable x
   

Let's rock and roll....
 

We will now discuss:

  1. How Java implements the parseInt( ) method that converts a number string into its 2s complement representation

  2. How Java implements the toString( ) method that converts a signed integer 2s complement representation into a number string (so the integer can be printed out)