Parser for signed overpunch values?

前端 未结 7 1333
南旧
南旧 2021-01-06 01:19

I am working with some old data imports and came across a bunch of data from an external source that reports financial numbers with a signed overpunch. I\'ve seen alot, but

相关标签:
7条回答
  • 2021-01-06 02:01

    Zoned decimal is easy and requires no char manipulation.

    private int ConvertOverpunch(byte[] number)
    {
        // Works for EBCDIC or ASCII, all charsets
        int rtnVal = 0;
        for(int i = 0; i<number.length; i++)
        {
           int digit = 0x0f & number[i];
           rtnVal = (rtnVal * 10) + digit;
        }
    
        // Extract sign
        // This works in EBCDIC
        // Need to find out what your sign is in ASCII
        if(0xD0 & number[number.length-1])
        {
           rtnVal *= -1;
        }   
    
        return rtnVal;
    }
    
    0 讨论(0)
提交回复
热议问题