This discussion is archived
1 Reply Latest reply: Mar 11, 2013 3:46 AM by EJP RSS

Convert String to BCD?

user8744860 Newbie
Currently Being Moderated
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 Guru
    Currently Being Moderated
    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.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points