Re: Convert Hexadecimal To String
Velichko Yuriy <[email protected]>
| Newsgroups | gmane.comp.db.tds.freetds |
|---|---|
| Message-ID | <CAN=WvWt5nqzoA9QJuqnhK+pw2qmtu7mqywSF5O5cJQ_ZYDHBRQ@mail.gmail.com> |
Thanks! On 24 September 2013 21:49, John Boia <[email protected]> wrote: > 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 > > [email protected] > > http://lists.ibiblio.org/mailman/listinfo/freetds > > _______________________________________________ > FreeTDS mailing list > [email protected] > http://lists.ibiblio.org/mailman/listinfo/freetds > -- Best Regards!