A
Angus
Hello
I have an unsigned char[14] and I want to convert the individual array
values into hex and copy to a std::string.
The array does not always hold 14 values - but I do know the length of
the data - obviously up to 14 chars.
An example is an array of six items with decimal values: 0, 10, 228,
164, 72, 11. I want to convert these values to hex and copy to a
string. Eg 000AE4A4480B - which the astute might recognise as a MAC
address.
I tried:
unsigned char cval = 10; // A
std::strstream str;
str << std::hex << cval << std::endl;
std::cout << str.str;
But that outputs 1 for some reason.
As does this:
unsigned char cvals[6];
// populate values
str << std::hex << cvals << std::endl;
std::cout << str.str;
also outputs 1 !
How should I be doing this?
I have an unsigned char[14] and I want to convert the individual array
values into hex and copy to a std::string.
The array does not always hold 14 values - but I do know the length of
the data - obviously up to 14 chars.
An example is an array of six items with decimal values: 0, 10, 228,
164, 72, 11. I want to convert these values to hex and copy to a
string. Eg 000AE4A4480B - which the astute might recognise as a MAC
address.
I tried:
unsigned char cval = 10; // A
std::strstream str;
str << std::hex << cval << std::endl;
std::cout << str.str;
But that outputs 1 for some reason.
As does this:
unsigned char cvals[6];
// populate values
str << std::hex << cvals << std::endl;
std::cout << str.str;
also outputs 1 !
How should I be doing this?