9 Replies Latest reply: Apr 6, 2011 2:57 AM by YoungWinston RSS

    How to convert BCD to ascii

    852893
      Hello,
      Please help me, I want to decode a file (coded in BCD) to a readable format (ascii)?
      Deatailed information of the coded file:
      Data Representation
      Data representation: Binary, Binary Coded Decimal (BCD), International Standards Organization (ISO) and Telephony BCD (TBCD) characters

      Numeral presentation: Left-adjusted with trailing #F (where required)

      Text presentation: Left-adjusted with trailing spaces (where required)

      Filler: Spaces for ISO characters and #F for BCD numbers and TBCD string

      Thanks ahead!
        • 1. Re: How to convert BCD to ascii
          EJP
          BCD is two digits per byte, 4 bits per digit. For example a byte of 0x33 means the decimal value 33. You have to process 4 bits at a time. These are called 'nibbles' - small bytes - geddit?. This is complicated by the fact that the sign is at the end, which means that there may be an odd number of digit nibbles ... The sign nibble if present is encoded as 0xd meaning negative or 0xc meaning positive. There are other possibilities, see Packed BCD, a.k.a. Cobol COMP-3 format. This all falls out of the IBM 360 hardware, possibly the IBM 7044 hardware before it. There are numerous public-domain BDC libraries in existence, and at least one for Java.
          • 2. Re: How to convert BCD to ascii
            DarrylBurke
            Don't double post. Your other thread on this forum has been locked.

            db
            • 3. Re: How to convert BCD to ascii
              DarrylBurke
              Double cross posted. Or should that be cross double posted?
              http://www.java-forums.org/new-java/41891-how-convert-bcd-ascii.html#post194881
              http://www.java-forums.org/advanced-java/41892-how-convert-bcd-ascii.html#post194882

              Any more?

              db
              • 4. Re: How to convert BCD to ascii
                jschellSomeoneStoleMyAlias
                849890 wrote:
                Hello,
                Please help me, I want to decode a file (coded in BCD) to a readable format (ascii)?
                Deatailed information of the coded file:
                Data Representation
                Data representation: Binary, Binary Coded Decimal (BCD), International Standards Organization (ISO) and Telephony BCD (TBCD) characters

                Numeral presentation: Left-adjusted with trailing #F (where required)

                Text presentation: Left-adjusted with trailing spaces (where required)

                Filler: Spaces for ISO characters and #F for BCD numbers and TBCD string
                To be clear that file has fields. The values in the fields are BCD.

                So you must do the following.
                1. Read a field
                2. Decode the field. And deal with padding.
                3. Go to step 1 until no more fields are left.

                And the above description does not cover either what the fields represent nor how to determine how long they are.
                • 5. Re: How to convert BCD to ascii
                  tschodt
                  Typically a single bit encoding odd/even (number of address signals) is associated with an ISUP BCD (TBCD) encoded number.
                  The filler can be 0 rather than F in some contexts.
                  | | Ascii | | BCD | | ISUP BCD | |
                  | | 1 | | 1F | | F1 | |
                  | | 12 | | 12 | | 21 | |
                  | | 123 | | 12 3F | | 21 F3 | |
                  | | 1234 | | 12 34 | | 21 43 | |
                  | | 12345 | | 12 34 5F | | 21 43 F5 | |
                  | | 123456 | | 12 34 56 | | 21 43 65 | |
                  | | 1234567 | | 12 34 56 7F | | 21 43 65 F7 | |
                  | | 12345678 | | 12 34 56 78 | | 21 43 65 87 | |
                  | | 123456789 | | 12 34 56 78 9F | | 21 43 65 87 F9 | |
                  | | etc. | | | | | |
                  • 6. Re: How to convert BCD to ascii
                    EJP
                    Is that the native Intel BCD format? Never heard of it otherwise, and I spent years of my life with BCD.
                    • 7. Re: How to convert BCD to ascii
                      tschodt
                      EJP wrote:
                      Is that the native Intel BCD format?
                      AFAIK it has nothing to do with Intel.
                      Never heard of it otherwise, and I spent years of my life with BCD.
                      It is specified in ITU-T Recommendation Q.763.
                      It is used with ISDN and SS7 ISUP messaging.
                      • 8. Re: How to convert BCD to ascii
                        EJP
                        Ah, good old Q.763. Those were the days ...
                        • 9. Re: How to convert BCD to ascii
                          YoungWinston
                          tschodt wrote:
                          Typically a single bit encoding odd/even (number of address signals) is associated with an ISUP BCD (TBCD) encoded number.
                          The filler can be 0 rather than F in some contexts.
                          And for signed BCD, it could also be C/D. Gawd, I thought I'd left all that behind in '91 :-).

                          Winston