BitsToHexStr
convert a vector of 1's and 0's to a hex string
bool BitsToHexStr( const vector<byte> & vn, string & strHex )
true if succeed
EX1
void BitsHex_BitsToHexStr_ex1() { vector<byte> vb; int nTotal = 20; //the vector will be converted to 5 Hex chars. srand( GetTickCount() ); for ( int ii = 0; ii < nTotal; ii++ ) { byte tb = rand() % 2; vb.Add(tb); } string strHex; BitsHex bh; if ( !bh.BitsToHexStr(vb, strHex) ) { printf("Fail to convert vector to Hex string."); return; } printf("vector {%d, ", vb[0]); for ( ii = 1; ii < nTotal - 1; ii++ ) printf("%d, ", vb[ii]); printf("%d} is convert to Hex string as follows:\n", vb[ii]); printf("%s\n", strHex); return; }
origin.h