Converting zoned decimal to comp-3 is pretty simple - flip the nibbles of the low byte and separate a large chunk of all the other bytes.
Consider the number 12345 - in the packed decimal notation, which will be x'12345C 'or x'12345F' (both C and F are +, AB and D are -). When you turned it into a zoned decimal, you flipped the lower nibble and inserted "F" in the high piece between each digit. Including it in x'F1F2F3F4C5 '.
To convert it back, you just cancel the process. Using java, it will look like this:
byte[] myDecimal = { 0xF1, 0xF2, 0xF3, 0xF4, 0xF5 }; byte[] myPacked = new byte[3];
source share