c# - How to convert unpacked decimal back to COMP-3? -
i had asked question converting comp fields, did not answer.
i hope stack-overflow can me on question.
i succeeded in converting comp-3 decimal. need in converting unpacked decimal comp-3, in high level programming language, preferably in java or c#.net.
in packed decimal -123 represented x'123d' (the last nyble c,d or f being sign). 1 of simplest ways handle packed decimal convert bytes hex string (or vice versa required) use normal string manipulation. may not efficient easy implement.
so convert integer (value) packed decimal (note: have not tested code)
string sign = "c"; if (value < 0) { sign = "d"; value = -1 * value; } string val = value + "d" byte[] comp3bytes = new biginteger(val, 16).tobytearray(); following example code converting to/from comp3 retrieve packed decimal array of bytes see method getmainframepackeddecimal in http://record-editor.svn.sourceforge.net/viewvc/record-editor/source/jrecord/src/net/sf/jrecord/common/conversion.java?revision=3&view=markup
and set packed decimal see setfield in http://record-editor.svn.sourceforge.net/viewvc/record-editor/source/jrecord/src/net/sf/jrecord/types/typepackeddecimal.java?revision=3&view=markup
both routines take array of bytes, start position , either length of field position.
there other examples of doing on web (jranch think has code doing conversion well), bit of googling.
Comments
Post a Comment