C言語にてバイナリデータを16進文字列に変換する
の続きです。
Boost はC++用のソフトウェアライブラリです。
Boost には、hex()/unhex() などの関数がある。
下記を参考にした。
int main() { std::string s = "abc"; std::string out; boost::algorithm::hex(s, std::back_inserter(out)); std::cout << out << std::endl; }
1行で記述できる。
このコードでは、std::string だが、
std::vector でもよい。
std::vector<char> bin std::vector<char> hex; boost::algorithm::hex(bin, std::back_inserter(hex));
サンプルコードを Guthub に公開した。
https://github.com/ohwada/MAC_cpp_Samples/tree/master/boost/algorithm/hex