int _helpper_Hex2Char(unsigned char & p_cChar,unsigned char p_Value,int & p_nOdd)
{
p_cChar&=0xf0;
p_Value&=0x0f;
p_cChar|=p_Value;
if(p_nOdd++%2) p_cChar<<=4; //first part
return p_nOdd%2?1:0; //if it is odd, then index need to +1 , other wise, index +0;
}
string _helper_Hex2Buffer(string p_sHexStr)
{
string sReturn = "";
unsigned char *buf=new unsigned char[p_sHexStr.length()];
memset(buf,0,p_sHexStr.length());
int nIndex=0;
int nOdd=1;
for (int i = 0; i < p_sHexStr.length (); ++i)
{
switch (p_sHexStr [i])
{
case '0':
{
nIndex+=_helpper_Hex2Char(buf[nIndex],0x00,nOdd);
break;
}
case '1':
{
nIndex+=_helpper_Hex2Char(buf[nIndex],0x01,nOdd);
break;
}
case '2': nIndex+=_helpper_Hex2Char(buf[nIndex],0x02,nOdd); break;
case '3': nIndex+=_helpper_Hex2Char(buf[nIndex],0x03,nOdd); break;
case '4': nIndex+=_helpper_Hex2Char(buf[nIndex],0x04,nOdd); break;
case '5': nIndex+=_helpper_Hex2Char(buf[nIndex],0x05,nOdd); break;
case '6': nIndex+=_helpper_Hex2Char(buf[nIndex],0x06,nOdd); break;
case '7': nIndex+=_helpper_Hex2Char(buf[nIndex],0x07,nOdd); break;
case '8': nIndex+=_helpper_Hex2Char(buf[nIndex],0x08,nOdd); break;
case '9': nIndex+=_helpper_Hex2Char(buf[nIndex],0x09,nOdd); break;
case 'a': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0a,nOdd); break;
case 'b': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0b,nOdd); break;
case 'c': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0c,nOdd); break;
case 'd': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0d,nOdd); break;
case 'e': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0e,nOdd); break;
case 'f': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0f,nOdd); break;
default:
continue;
}
}
sReturn.append((char *)buf,nIndex);
delete buf;
return sReturn;
}