1 Reply Latest reply: Mar 11, 2013 5:46 AM by EJP RSS

    Convert String to BCD?

    user8744860
      Hi,

      I am decoding a byte array BCD to int using the following code :

                Input : byte [] bcd {

                StringBuilder builder = new StringBuilder();
                for (byte v : bcd) {
                     System.out.println( v + " -- " + Integer.toHexString(v &0xff));
                     builder.append(Integer.toHexString(v &0xff));
                }
      }

      where builder is the final integer . For example for = new byte [] {19,1,49,9,34,32};
      we get builder = (1313192220).

      Now I have to encode this integer string back to a BCD array .
      How do I do this ?

      Please help!!!! really stuck

      Regards

      Abhinav
        • 1. Re: Convert String to BCD?
          EJP
          where builder is the final integer . For example for = new byte [] {19,1,49,9,34,32};
          For clarity, that is {0x13, 0x01, 0x31, 0x09, 0x22, 0x20}
          we get builder = (1313192220).
          Incorrect. See above.
          Now I have to encode this integer string back to a BCD array .
          Impossible, and pointless, until you get the conversion to string representation correct. Once you understand how to do that, and what it actually means, the converse is child's play.