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 15:33, local time: 2024/12/2 02:03,
18.188.219.131: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://ecomorder.com/techref/language/ccpp/cppref/examples/2hex_cc.htm"> C++ Programming Example Convert to Hex</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to ecomorder.com! |
.