//将BCD码转为ASC串(0-f可转)
//NUMS==SOUR的BCD码数
//例:if sour=9999,nums=4 then dest=0x39,0x39,0x39,0x39
// if sour=99999f nums=5,then dest=0x39,0x39,0x39,0x39,0x39 "f"is cut
int bcd_to_asc(char *sour,int nums,char *dest)
{
int i,len,oddno=0;
len=nums/2+nums%2;
if((nums%2)!=0)
oddno=1;
memset(dest,'/0',nums);
for(i=0;i<len;i++)
{
*(dest+2*i)=(*(sour+i)>>4)+0x30;
if((i<(len-1))||((i==(len-1))&&(oddno==0)))
*(dest+2*i+1)=(*(sour+i)&0x0f)+0x30;
}
return 0;
}
//NUMS==SOUR的BCD码数
//例:if sour=9999,nums=4 then dest=0x39,0x39,0x39,0x39
// if sour=99999f nums=5,then dest=0x39,0x39,0x39,0x39,0x39 "f"is cut
int bcd_to_asc(char *sour,int nums,char *dest)
{
int i,len,oddno=0;
len=nums/2+nums%2;
if((nums%2)!=0)
oddno=1;
memset(dest,'/0',nums);
for(i=0;i<len;i++)
{
*(dest+2*i)=(*(sour+i)>>4)+0x30;
if((i<(len-1))||((i==(len-1))&&(oddno==0)))
*(dest+2*i+1)=(*(sour+i)&0x0f)+0x30;
}
return 0;
}