Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Convert EBCDIC to ASCII and vice versa

Convert EBCDIC to ASCII and vice versa

Scheduled Pinned Locked Moved C#
csharpdatabasedata-structureshelpquestion
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deep7
    wrote on last edited by
    #1

    Hi, In my C# application, I need to convert EBCDIC data to ASCII. This EBCDIC data is stored as BLOB type in Teradata. This data also has packed decimals in it. I tried the code i found on internet, which simply converts EBCDIC to ASCII. In that there a interger array of 256 characters only. But the characters which i need to convert, char chrItem = Convert.ToChar(strEbcidic.Substring(i, 1)); returns number much higher then 256. So i get 'index out of bound of array exception'. The EBCDIC characters include ' ÁõÁõöôùô@@@@ðóùòùùðñ@ððððð' also. Could any one please help me out here? Thanks, Deepa

    OriginalGriffO S 2 Replies Last reply
    0
    • D deep7

      Hi, In my C# application, I need to convert EBCDIC data to ASCII. This EBCDIC data is stored as BLOB type in Teradata. This data also has packed decimals in it. I tried the code i found on internet, which simply converts EBCDIC to ASCII. In that there a interger array of 256 characters only. But the characters which i need to convert, char chrItem = Convert.ToChar(strEbcidic.Substring(i, 1)); returns number much higher then 256. So i get 'index out of bound of array exception'. The EBCDIC characters include ' ÁõÁõöôùô@@@@ðóùòùùðñ@ððððð' also. Could any one please help me out here? Thanks, Deepa

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      I think the problem may be that your input is not EBCDIC - ebcdic is an 8-bit code so only has characters 000 to 255. Wiki on EBCDIC[^]

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      D 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        I think the problem may be that your input is not EBCDIC - ebcdic is an 8-bit code so only has characters 000 to 255. Wiki on EBCDIC[^]

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        D Offline
        D Offline
        deep7
        wrote on last edited by
        #3

        Hi, Yes, none of these characters in the file are in the 255 codes of EBCDIC. As i had mentioned earlier, the file from the BLOB, contains packed decimal also. Are you sure its not EBCDIC, when i do .ToCharArray() i get like: [0]: 22909 '好' [1]: 8224 '†' [2]: 8256 '⁀' [3]: 8592 '←' [4]: 879 'ͯ' [5]: 12629 'ㅕ' [6]: 16527 '䂏' [7]: 16448 '䁀' [8]: 16448 '䁀' [9]: 16448 '䁀' [10]: 16448 '䁀' [11]: 16448 '䁀' [12]: 16448 '䁀' [13]: 65533 '�' [14]: 49605 '쇅' [15]: 16601 '䃙' [16]: 16448 '䁀' [17]: 16448 '䁀' [18]: 16448 '䁀' [19]: 16448 '䁀' [20]: 16448 '䁀' [21]: 16448 '䁀' [22]: 16448 '䁀' [23]: 62448 '' [24]: 63216 '' [25]: 63220 '' [26]: 63473 '' [27]: 63216 '' [28]: 62451 '' [29]: 61689 '' [30]: 54769 '헱' [31]: 16448 '䁀' [32]: 16448 '䁀' [33]: 16448 '䁀' [34]: 16448 '䁀' So their character codes are greater then 255. How to resolve this?

        A 1 Reply Last reply
        0
        • D deep7

          Hi, Yes, none of these characters in the file are in the 255 codes of EBCDIC. As i had mentioned earlier, the file from the BLOB, contains packed decimal also. Are you sure its not EBCDIC, when i do .ToCharArray() i get like: [0]: 22909 '好' [1]: 8224 '†' [2]: 8256 '⁀' [3]: 8592 '←' [4]: 879 'ͯ' [5]: 12629 'ㅕ' [6]: 16527 '䂏' [7]: 16448 '䁀' [8]: 16448 '䁀' [9]: 16448 '䁀' [10]: 16448 '䁀' [11]: 16448 '䁀' [12]: 16448 '䁀' [13]: 65533 '�' [14]: 49605 '쇅' [15]: 16601 '䃙' [16]: 16448 '䁀' [17]: 16448 '䁀' [18]: 16448 '䁀' [19]: 16448 '䁀' [20]: 16448 '䁀' [21]: 16448 '䁀' [22]: 16448 '䁀' [23]: 62448 '' [24]: 63216 '' [25]: 63220 '' [26]: 63473 '' [27]: 63216 '' [28]: 62451 '' [29]: 61689 '' [30]: 54769 '헱' [31]: 16448 '䁀' [32]: 16448 '䁀' [33]: 16448 '䁀' [34]: 16448 '䁀' So their character codes are greater then 255. How to resolve this?

          A Offline
          A Offline
          Alan Balkany
          wrote on last edited by
          #4

          The problem is that chars in .NET are Unicode, which is generally two bytes. Using a byte array instead of a char array might solve your problem.

          1 Reply Last reply
          0
          • D deep7

            Hi, In my C# application, I need to convert EBCDIC data to ASCII. This EBCDIC data is stored as BLOB type in Teradata. This data also has packed decimals in it. I tried the code i found on internet, which simply converts EBCDIC to ASCII. In that there a interger array of 256 characters only. But the characters which i need to convert, char chrItem = Convert.ToChar(strEbcidic.Substring(i, 1)); returns number much higher then 256. So i get 'index out of bound of array exception'. The EBCDIC characters include ' ÁõÁõöôùô@@@@ðóùòùùðñ@ððððð' also. Could any one please help me out here? Thanks, Deepa

            S Offline
            S Offline
            Scott Barbour
            wrote on last edited by
            #5

            I highly recommend using Jon Skeet's EBCDIC encoding library[^] We have been using this for years. You basically just set up Encoding objects and pass them into Stream objects. Granted, this is VB.NET code, but it should still make sense:

            Dim inputEncoding As Encoding = EbcdicEncoding.GetEncoding("EBCDIC-US")
            Dim outputEncoding = Encoding.ASCII
            Dim inputReader As StreamReader
            Dim outputWriter As StreamWriter
            inputReader = New StreamReader(inputFile, inputEncoding)
            outputWriter = New StreamWriter(outputFile, False, outputEncoding)

            I don't claim to be a know it all, for I know that I am not...

            I usually have an answer though.

            I 1 Reply Last reply
            0
            • S Scott Barbour

              I highly recommend using Jon Skeet's EBCDIC encoding library[^] We have been using this for years. You basically just set up Encoding objects and pass them into Stream objects. Granted, this is VB.NET code, but it should still make sense:

              Dim inputEncoding As Encoding = EbcdicEncoding.GetEncoding("EBCDIC-US")
              Dim outputEncoding = Encoding.ASCII
              Dim inputReader As StreamReader
              Dim outputWriter As StreamWriter
              inputReader = New StreamReader(inputFile, inputEncoding)
              outputWriter = New StreamWriter(outputFile, False, outputEncoding)

              I don't claim to be a know it all, for I know that I am not...

              I usually have an answer though.

              I Offline
              I Offline
              ishtine18
              wrote on last edited by
              #6

              how to install the Jon Skeet's EBCDIC encoding library[

              F 1 Reply Last reply
              0
              • I ishtine18

                how to install the Jon Skeet's EBCDIC encoding library[

                F Offline
                F Offline
                frank_a320
                wrote on last edited by
                #7

                Try This #region public static byte[] ConvertAsciiToEbcdic(byte[] asciiData) public static byte[] ConvertAsciiToEbcdic(byte[] asciiData) { // Create two different encodings. Encoding ascii = Encoding.ASCII; Encoding ebcdic = Encoding.GetEncoding("IBM037"); //Retutn Ebcdic Data return Encoding.Convert(ascii, ebcdic, asciiData); } #endregion #region public static byte[] ConvertEbcdicToAscii(byte[] ebcdicData) public static byte[] ConvertEbcdicToAscii(byte[] ebcdicData) { // Create two different encodings. Encoding ascii = Encoding.ASCII; Encoding ebcdic = Encoding.GetEncoding("IBM037"); //Retutn Ascii Data return Encoding.Convert(ebcdic, ascii, ebcdicData); } #endregion

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups