Home > Back-end >  Return hexadecimal data C
Return hexadecimal data C

Time:09-25

Now have a hexadecimal data STR="B5 62 06 00 00 14 01 00 00 00 D0 08 00 00 00 C2 07 00 00 03 01 00 00 00 00 00 C0 7 e",
Call a function returns the hexadecimal data not return a string, can you tell me how to achieve?

CodePudding user response:

Is to convert hexadecimal string to integer array? Read characters from a string once and then converted to a decimal line

CodePudding user response:

 
Unsigned char * __fastcall StrToHex (const AnsiString& HexStr)
{
Unsigned char * result=new unsigned char (hexStr. The Length ()/2);
Unsigned char * pbufs=the result;

Char * pData=(https://bbs.csdn.net/topics/hexStr.UpperCase). C_str ();

for(int i=0; i {
Unsigned char val=pData [I] - '0';

If (val & gt; 0 xf)
Val -=7;

If (I % 2==0)
{
* pbufs=val.
* pbufs & lt; <=4;
}
The else
{
* pbufs |=val;
PBuf++;
}
}

return result;
}

Pay attention to release the returned data buffer,
  • Related