Change Ascii code to Hex code
Make_Ascii2Hex(_In_ CONST TCHAR *pData, _In_ unsigned int nLen, _Out_ BYTE *pOutputData, _Out_ DWORD *pRspSize)
{
WORD i = 0, j = 0, k = 0, ret = 0;
WORD hex_data1 = 0;
WORD hex_data2 = 0;
WORD hex_data3 = 0;
TRY
{
for (i = 0; i < nLen; i++)
{
if (pData[i] != 0x20)
{
if (j == 0)
{
hex_data1 = byCode2AsciiValue(pData[i]) << 4;
j++;
}
else
{
hex_data2 = byCode2AsciiValue(pData[i]);
hex_data3 = hex_data1 | hex_data2;
*pOutputData++ = (BYTE)hex_data3;
hex_data1 = 0;
hex_data2 = 0;
hex_data3 = 0;
j = 0;
k++;
}
}
}
}
CATCH_ALL(e)
{
ret = SUP300_EXCEPTION_ERROR;
}
END_CATCH_ALL
*pRspSize = k;
return (LastErrorCode = ret);
}
Change to Ascii value
byCode2AsciiValue(_In_ TCHAR cData)
{
BYTE byAsciiValue;
if (('0' <= cData) && (cData <= '9'))
{
byAsciiValue = cData - '0';
}
else if (('A' <= cData) && (cData <= 'F'))
{
byAsciiValue = (cData - 'A') + 10;
}
else if (('a' <= cData) && (cData <= 'f'))
{
byAsciiValue = (cData - 'a') + 10;
}
else
{
byAsciiValue = 0;
}
return byAsciiValue;
}