Converts a character or string into a hexidecimal string. The use of std::string
removes any need for dynamic allocation and pointer maintenance.
From:
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20525179.html
#include <string> using namespace std; string Byte2Hex(unsigned char c) { const char *CnvTbl = "0123456789ABCDEF"; string S; S = CnvTbl[c >> 8]; S += CnvTbl[c & 0x0F]; return S; } string String2Hex(const string &S) { const int StrLen = S.length(); string Result; for (int i = 0; i < StrLen; ++i) Result += Byte2Hex((unsigned char) S[i]); return Result; }
file: /Techref/language/ccpp/cppref/EXAMPLES/2hex_cc.htm, 1KB, , updated: 2006/3/31 16:33, local time: 2024/8/15 00:25,
18.222.182.191:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://techref.massmind.org/techref/language/ccpp/cppref/EXAMPLES/2hex_cc.htm"> C++ Programming Example Convert to Hex</A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to techref.massmind.org! |
.