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';
}
{
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: HEX BIN
Subscribe to Posts [Atom]
Scrape It |