How to convert from EBCDIC to ASCII in C#.net

后端 未结 7 1189
时光取名叫无心
时光取名叫无心 2020-12-06 06:57

I have a value in EBCDIC format \"000000{\". I want to convert it into a.Net Int32 type. Can anyone let me know what I can do about it?? So my question is given a string tha

相关标签:
7条回答
  • 2020-12-06 07:22

    You're going to want to read up on binary-coded decimals, as that is what you are facing, and there are questions to answer before you can really code it.

    If the value is a single character, it may be as simple as getting the char number--but you need to know if the system is Big Endian (like most mainframes from which you would be getting EBDIC-encoded files) or Little Endian (like more modern OSes).

    If your integer value uses more than one character and includes the sign (as you mention), then it is more complex. Most likely, each half (or "nibble", or 4 bits) of each character represents the number--maybe 0 thru 9 or in hex 0 thru F, and the string is padded with zeros (nulls, actually) on the left, and the last nibble contains the sign. This system might be called Zoned Decimal in some parlance.

    All in all, I would recommend starting by reading this article, which should introduce you to how data is/was stored on COBOL-based mainframes, and get you moving the right direction.


    In C#, you may be able to do the conversion form the common Zoned Decimal (which sounds like the best fit for your incoming data as you have described it) by using int.Parse with the correct NumberStyles options, like this:

    int val = int.Parse(num, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite);
    
    0 讨论(0)
提交回复
热议问题