Hi, I don't mean to post a solution to this but I could not post code on the comments. Ihad written these two functions sometime ago for debugging. Not sure if they fit your needs. Also they can be improved and optimized. Hope they help you, the comments sort of explain what they do. With them you can convert a binary array of bytes to its ascii representation.
int iConvertBinArray2String( char* bBindata,
int iDataSize,
char* szDataString )
{
if (( bBindata == NULL )||(szDataString) == NULL )
return 1;
for(int i = 0; i < iDataSize ; i++)
{
char tmp[3];
memset(tmp,0,3);
sConvertHexBin2String((unsigned char)bBindata[i],(unsigned char*)tmp);
memcpy((szDataString+2*i),tmp,2);
}
return 0;
}
unsigned char* sConvertHexBin2String(unsigned char ch, unsigned char* buffer)
{
char tmp[3];
memset(tmp,0,3);
if ( (ch&0x0F) == 0 )
{
if ( ch == 0x00 )
{
tmp[0] = 0x30;
tmp[1] = 0x30;
tmp[2] = 0x00;
}
else
{
sprintf(tmp,"%x",ch);
if ( tmp[1] == 0 )
tmp[1] = 0x30;
}
}
else
if ( ((ch&0xF0)<<4) == 0 )
{
char cfix = 0x00;
sprintf(tmp,"%x",ch);
cfix = tmp[0];
tmp[0] = 0x30;
tmp[1] = cfix;
}
else
sprintf(tmp,"%x",ch);
memcpy(buffer,tmp,3);
return buffer;
}