#include <iostream>
#include <iomanip>
#include <vector>
#include <sstream>
typedef unsigned char BYTE;
int main() {
std::istringstream iss("1,3,8,b,e,ff,10");
std::vector<BYTE> dataValues;
unsigned int num = 0;
while(iss >> std::hex >> num || !iss.eof())
{
if(iss.fail())
{
iss.clear();
char dummy;
iss >> dummy;
continue;
}
if(num <= 0xff) {
dataValues.push_back(static_cast<BYTE>(num));
}
else {
// Error single byte value expected
}
}
std::cout << std::hex << std::setfill('0');
for(std::vector<BYTE>::const_iterator it = dataValues.begin();
it != dataValues.end();
++it) {
std::cout << "0x" << std::setw(2) << static_cast<unsigned int>(*it) << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHNzdHJlYW0+Cgp0eXBlZGVmIHVuc2lnbmVkIGNoYXIgQllURTsKCmludCBtYWluKCkgewoKICAgIHN0ZDo6aXN0cmluZ3N0cmVhbSBpc3MoIjEsMyw4LGIsZSxmZiwxMCIpOwogICAgc3RkOjp2ZWN0b3I8QllURT4gZGF0YVZhbHVlczsKICAgIAogICAgdW5zaWduZWQgaW50IG51bSA9IDA7CiAgICB3aGlsZShpc3MgPj4gc3RkOjpoZXggPj4gbnVtIHx8ICFpc3MuZW9mKCkpIAogICAgewogICAgICAgIGlmKGlzcy5mYWlsKCkpIAogICAgICAgIHsKICAgICAgICAgICAgaXNzLmNsZWFyKCk7CiAgICAgICAgICAgIGNoYXIgZHVtbXk7CiAgICAgICAgICAgIGlzcyA+PiBkdW1teTsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGlmKG51bSA8PSAweGZmKSB7CiAgICAgICAgICAgIGRhdGFWYWx1ZXMucHVzaF9iYWNrKHN0YXRpY19jYXN0PEJZVEU+KG51bSkpOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAJLy8gRXJyb3Igc2luZ2xlIGJ5dGUgdm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