This content has been marked as final. Show 9 replies
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.
849890 wrote:To be clear that file has fields. The values in the fields are BCD.
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: 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
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.
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. | | | | | |