Skip to Content.
Sympa Menu

freetds - Re: [freetds] Convert Hexadecimal To String

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: John Boia <jboia AT stsci.edu>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Convert Hexadecimal To String
  • Date: Tue, 24 Sep 2013 18:49:25 +0000

Try this. I found it elsewhere and augmented it.

std::string bin_to_hex( const unsigned char *input, size_t len )
{
static const char* const lut = "0123456789ABCDEF";

// Convert each byte to 2-char hex representation
std::string output;
output.reserve(2 * len);
volatile unsigned char c;
for (size_t i = 0; i < len; ++i)
{
c = input[i];
output.push_back(lut[c >> 4]);
output.push_back(lut[c & 15]);
}

// Trim excess nulls from end of binary string
bool done = false;
while( !done ) {
size_t pos = output.rfind("0000000000000000");
if ( pos != std::string::npos ) {
output.erase(pos,16);
} else {
done = true;
}
}

return output;
}


On Sep 24, 2013, at 13:25 , Velichko Yuriy wrote:

> Hello!
>
> I use method dbdata() to get data returned by dbsqlexec().
> To fetch binary data I use dbconvert() to convert data into SYBCHAR.
> This method gives the hexadecimal string.
>
> Can you suggest me how to convert this string to character string?
>
> For example MySQL client has build-in method for this purpose:
> mysql_hex_string();
>
> freetds (dblib) has something similar?
>
> Thanks!
>
> --
> Best Regards!
> _______________________________________________
> FreeTDS mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds





Archive powered by MHonArc 2.6.24.

Top of Page