Friday, July 13, 2007

Transfer the bin to the hex code

void bin2hex( const void* in_buffer, int in_size, char * out_buffer )
{
size_t i, k;
const unsigned char* in_chars = (const unsigned char *) in_buffer;

for ( i = 0; i < in_size; ++ i )
{
#ifdef NETWARE
unsigned char chars[2];
chars[0] = ( in_chars[i] >> 4 ) & 0x0f;
chars[1] = in_chars[i] & 0x0f ;
#else
unsigned char chars[2] = { ( in_chars[i] >> 4 ) & 0x0f,
in_chars[i] & 0x0f };
#endif
for ( k = 0; k < 2; ++ k )
{
if ( chars[k] < 10 )
out_buffer[ i * 2 + k ] = (char) ('0' + chars[k] );
else
out_buffer[ i * 2 + k ] = (char) ( 'A' + chars[k] - 10 );
}
}

out_buffer[ i * 2 ] = '\0';
}

Labels:


Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]

Scrape It
Free Hit Counters
Scrape It