HexStrToByte

void HexStrToByte(const char* source, unsigned char* dest, int sourceLen)
{
 short i;
 unsigned char highByte, lowByte;

for (i = 0; i < sourceLen; i += 2)
{
	highByte = source[i];
	lowByte  = source[i + 1];

	if (highByte >= 'a')
		highByte = highByte - 'a' + 10;
	else
          highByte -= '0';

    if (lowByte >= 'a')
        lowByte = lowByte - 'a' + 10;
    else
        lowByte -= '0';

    dest[i / 2] = (highByte << 4) | lowByte;
     }
      return ;
 }

char Hexstring[64]="7e004179000d016\0";
char Binarystring[256]={0};
HexStrToByte(Hexstring,Binarystring,strlen(Hexstring));

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章