Author: Zhu Ke
Email: zhukefeng@iboxpay.com
Reprint please indicate the source: HTTP://BLOG.CSDN.NET/LINUX_ZKF
nsstring* ASCIICONVERTFROMBCD (NSString *bcdstring)
{
int len = bcdstring.length;
Char pdupack[len/2+1], *pdustr;
Bzero (Pdupack, len/2+1);
PDUSTR = (char *) [bcdstring cstringusingencoding:nsutf8stringencoding];
for (int i=0 i <len; i+=2) {
Char Tempchar;
Tempchar = Pdustr[i];
if ((Tempchar <= ' 9 ') && (Tempchar >= ' 0 ')) {
Tempchar = Tempchar & 0x0f;
}
else {
Tempchar = (Tempchar & 0x0f) + 9;
}
PDUPACK[I/2] = Tempchar;
Tempchar = pdustr[i+1];
if ((Tempchar <= ' 9 ') && (Tempchar >= ' 0 ')) {
Tempchar = Tempchar & 0x0f;
}
else {
Tempchar = (Tempchar & 0x0f) + 9;
}
PDUPACK[I/2] = ((PDUPACK[I/2] << 4) & 0xf0) + Tempchar;
}
nsstring* retstring = [[NSString alloc] Initwithcstring:pdupack encoding:nsutf8stringencoding];
return retstring;
}