1

I am now working in a payment gateway .ISO 8583 messaging system we are using . I am facing some problem that I describle below : my binary data is :

0111101010111010000001000000000100001110111000001100000000000000 

I need to convert it Hexadecimal value (8 bytes):

7A BA 04 01 0E E0 C0 00 

then I need to Transferred as 16 EBCDIC characters (hexadecimal):

F7 C1 C2 C1 F0 F4 F0 F1 F0 C5 C5 F0 C3 F0 F0F0

then I need Transferred as 16 ASCII characters (hexadecimal):

37 41 42 41 30 34 30 31 30 45 45 30 43 30 30 30

my problem is how can I convert this binary data EBCDIC character and ASCII character . If anyone help me its very needed

tapos ghosh
  • 2,114
  • 23
  • 37

1 Answers1

1

With the help of this function: You can first convert the byte array to a hexadecimal string, then convert this to the EBCDIC encoding and in the end you can take again the hexadecimal bytecodes of the characters:

    var hexdata = new[] { 0x7A, 0xBA, 0x04, 0x01, 0x0E, 0xE0, 0xC0, 0x00 };    
    var asciiString = string.Join("", hexdata.Select(num => num.ToString("X2")));
    var asciiBytes = asciiString.Select(ch => (byte)ch).ToArray(); // It is safe, as we cannot have any unicode characters here

    var ebcdicData = ConvertAsciiToEbcdic(asciiBytes);

    var ebcdicString = string.Join(" ", ebcdicData.Select(ch => ((byte)ch).ToString("X2")));    
    var asciiHexString = string.Join(" ", asciiBytes.Select(ch => ((byte)ch).ToString("X2")));
BotondF
  • 190
  • 1
  • 11