Hi, I've a small function (see below) to convert hex encoded stream of bytes to binary stream. My question is, could anyone suggest equivalent function but implemented with help of Boost libraries? I don't have any particular goal or requirement like better performance, simpler implementation, etc. I'm just curious what Boost components I can use to achieve this kind of tasks. I've scanned the archives but there seem to be not much on encoding/decoding hex string, just: http://lists.boost.org/boost-users/2007/11/32269.php // hex-to-bin function #include <sstream> #include <string> #include <vector> typedef std::vector<unsigned char> ewkb_t; // hexstr [in] - string with hex encoded bytes // bytes [out] - output in binary form void hex_to_bin(std::string const& hexstr, ewkb_t bytes) { bytes.clear(); for(std::string::size_type i = 0; i < hexstr.size() / 2; ++i) { std::istringstream iss(hexstr.substr(i * 2, 2)); unsigned int n; iss >> std::hex >> n; bytes.push_back(static_cast<unsigned char>(n)); } } Best regards, -- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org
participants (1)
-
Mateusz Loskot