2.2.7.2.2 BitsHex::HexStrToBits

Description

convert a hex string to a vector of 1's and 0's

Syntax

bool HexStrToBits( const string & strHex, vector<byte> & vn )

Parameters

strHex
[input] the string to be converted
vn
[output]the byte vector to store byte values

Return

true if succeed

Examples

EX1

void BitsHex_HexStrToBits_ex1()
{
	string strHex = "E38C";
	vector<byte> vb;
	BitsHex bh;
	if ( bh.HexStrToBits(strHex, vb) )
	{
		printf("Hex string %s is convert to vector as follows:\n", strHex);
		int nTotal = vb.GetSize();
		printf("vector {%d, ", vb[0]);
		for ( int ii = 1; ii < nTotal - 1; ii++ )
			printf("%d, ", vb[ii]);
		printf("%d}\n", vb[ii]);
	}
	else
		printf("Fail to convert Hex string %s to byte vector.\n", strHex);
}

Remark

See Also

BitsHex::BitsToHexStr

Header to Include

origin.h