ebcdic to decimal function

BlackDice 0 Tallied Votes 197 Views Share

I don't know if this function may be helpful to anyone, but I just converted from a VB function recently to C++. I'm converting a text file string that is nine characters to a decimal value that has funny characters in it because it is exported from an old VAX. this function takes that string and returns it as a CString with either positive or negative value that you can then convert to an integer:

CString EBCDICToDecimal(CString strValue)
{
CString chr;
char cEnd;
int nLength = strValue.GetLength();
cEnd = strValue[nLength - 1];
chr = "";
if((cEnd >= 65) && (cEnd <= 73)) cEnd -= 16;
if(cEnd == 123) cEnd = 48;
if(cEnd == 125) 
{
chr = "-";
cEnd = 48;
}
if((cEnd >= 74) && (cEnd <= 82))
{
chr = "-";
cEnd -= 25;
}
strValue = chr + strValue.Left(strValue.GetLength() - 1) + cEnd;
return strValue;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.