10 pts.
 EBCDIC to Ascii conversion C#
Hi,

I am trying to convert EBCDIC to ASCII. The code which I used is converting the whole stream to ASCII however I am getting "????" for the missing characters..Is that because of double byte character set??

Can someone help me to resolve this issue??.

I tried with jon-skeet code as well but facing the same issue.

Thanks in advance.

Virbhadra.

 

 



Software/Hardware used:
C#
ASKED: November 11, 2010  10:03 AM
UPDATED: August 27, 2011  7:45 PM

Answer Wiki:
Try this
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); 
} 

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); 
}
Last Wiki Answer Submitted:  September 20, 2012  12:51 am  by  TomLiotta   108,055 pts.
All Answer Wiki Contributors:  TomLiotta   108,055 pts. , TabbyCool   30 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Encoding ascii = Encoding.ASCII;

ASCII might not be appropriate. UTF8Encoding might be better. The ASCII character set might not include everything.

Encoding ebcdic = Encoding.GetEncoding(“IBM037″);

IBM037 should work for US English encoding. However, if this is DBCS or some more involved encoding, the 037 set probably won’t work correctly. The actual encoding will need to be known. The encoding should either be sent with the file or data, or it should be agreed upon by the two sides of a conversation.

Be aware that some cooperation may be needed between sending and receiving side. Practically speaking, an encoding such as UTF8 ought to be agreed upon by both sides before exchange of data. Sending encoded data without advertising the encoding scheme gets real messy.

Tom

 108,055 pts.

 

i have 2 textBoxes and 1 button.
textbox1 has Ebcdis code
i want that when i click on button
textBox2 shows ascii code

how will i do that???

 10 pts.

 

That’s helpful Tom. I was wondering about this as well.

 0 pts.