how to convert decimal to Packed decimal/COMP-3

1.6k Views Asked by At

I need convert some decimal to PD6.2, then send it to Mainframe. It's very hard to find any function in C#. please help. Thanks a million

1

There are 1 best solutions below

7
On

See if this works

        public static void Main()
        {
            string lookup = "0123456789";
            int input = 123456789;
            string input_str = input.ToString();
            List<byte> output = new List<byte>();
            int index = 0;
            //odd number characters
            if (input_str.Length % 2 == 1)
            {
                output.Add((byte)lookup.IndexOf(input_str.Substring(index++, 1)));
            }
            for (int i = index; i < input_str.Length; i += 2)
            {
                output.Add((byte)((lookup.IndexOf(input_str.Substring(i, 1))) << 4 | lookup.IndexOf(input_str.Substring(i + 1, 1))));
            }



        }