由于工作需要,写了一个小程序,程序虽小,但是还是常用,呵呵,如下:
int
HexDecode( unsigned
char
*
instr,
int
inlen, unsigned
char
*
outstr )
{
int i = 0 ;
int j = 0 ;
while ( i < inlen )
{
if ( instr[i] >= ' a ' ) outstr[j] = instr[i] - 0x57 ;
else outstr[j] = instr[i] - ' 0 ' ;
outstr[j] = outstr[j] << 4 ;
i ++ ;
if ( instr[i] >= ' a ' ) outstr[j] = outstr[j] | (instr[i] - 0x57 );
else outstr[j] = outstr[j] | (instr[i] - ' 0 ' );
j ++ ;
i ++ ;
}
return j;
}
int HexEncode( unsigned char * instr, int inlen, unsigned char * outstr )
{
int i = 0 ;
int j = 0 ;
while ( i < inlen )
{
if ( (instr[i] & 0xF0 ) >= 0xA0 ) outstr[j] = (instr[i] >> 4 ) + 0x57 ;
else outstr[j] = (instr[i] >> 4 ) + ' 0 ' ;
j ++ ;
if ( (instr[i] & 0x0F ) >= 0x0A ) outstr[j] = (instr[i] & 0x0F ) + 0x57 ;
else outstr[j] = (instr[i] & 0x0F ) + ' 0 ' ;
i ++ ;
j ++ ;
}
return j;
}
{
int i = 0 ;
int j = 0 ;
while ( i < inlen )
{
if ( instr[i] >= ' a ' ) outstr[j] = instr[i] - 0x57 ;
else outstr[j] = instr[i] - ' 0 ' ;
outstr[j] = outstr[j] << 4 ;
i ++ ;
if ( instr[i] >= ' a ' ) outstr[j] = outstr[j] | (instr[i] - 0x57 );
else outstr[j] = outstr[j] | (instr[i] - ' 0 ' );
j ++ ;
i ++ ;
}
return j;
}
int HexEncode( unsigned char * instr, int inlen, unsigned char * outstr )
{
int i = 0 ;
int j = 0 ;
while ( i < inlen )
{
if ( (instr[i] & 0xF0 ) >= 0xA0 ) outstr[j] = (instr[i] >> 4 ) + 0x57 ;
else outstr[j] = (instr[i] >> 4 ) + ' 0 ' ;
j ++ ;
if ( (instr[i] & 0x0F ) >= 0x0A ) outstr[j] = (instr[i] & 0x0F ) + 0x57 ;
else outstr[j] = (instr[i] & 0x0F ) + ' 0 ' ;
i ++ ;
j ++ ;
}
return j;
}