3 Replies Latest reply: Jan 23, 2010 2:35 PM by 807580 RSS

    Convert Letters to Numbers

    807580
      Was wondering how to convert letters to numbers in java. We are working on a problem in class that has you input information for a cd. For example Title, Artist, Year and month produced, and then input a bar code number. I have the code down for all the inputs and then display what the user just entered.

      What i was wanting to do is take the Title and Artist inputs convert those letters to numbers then add the year and month on the end to create its own barcode.
        • 1. Re: Convert Letters to Numbers
          jschellSomeoneStoleMyAlias
          I presume that your real question is that you want to issue a bar code using a specification that includes alphas.

          Since barcodes have their own representation you need to map it.

          An efficient way to do that is a int array.

          Create an array that is 128 in size. That represents the ASCII character set. Each space in that character set will have one of the following values.
          - Negative one, this indicates there is no mapped value.
          - The binary representation of a bar code number

          (The above is based on a single barcode specification that I found which would allow mapping bits to a barcodes.)

          Then for each character in an input you use the array to either get the barcode value or report that the character is not allowed (or perhaps just remove it.)
          • 2. Re: Convert Letters to Numbers
            807580
            Fenhoff wrote:
            Was wondering how to convert letters to numbers in java. We are working on a problem in class that has you input
            Easiest way is to use Integer.parseInt(String) or Double.parseDouble(String)

            if you just have a char, you could try

            char ch = ...;
            int val = ch - '1' + 1;

            I'm not sure all the numbers (especially 0) are lined up the right way though.
            • 3. Re: Convert Letters to Numbers
              807580
              cross-posting earthcube:
              [http://www.java-forums.org/new-java/24963-converting-letters-numbers.html]