Skip to content

Commit a0758ab

Browse files
committed
Merge pull request daminetreg#6 from External/feature/to_hexstring_2
FEATURE: overloaded to_hexstring
2 parents 66e65a2 + 8b2c43f commit a0758ab

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pre/bytes/utils.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ namespace pre { namespace bytes {
6666

6767
return out;
6868
}
69+
70+
/**
71+
* \brief Converts any given byte string to a corresponding hexadecimal number in a string.
72+
* \param hex byte string
73+
*/
74+
inline std::string to_hexstring(const std::string& hex) {
75+
std::vector<char> bytes;
76+
for (unsigned int i = 0; i < hex.length(); i += 2) {
77+
std::string byteString = hex.substr(i, 2);
78+
char byte = (char) strtol(byteString.c_str(), NULL, 16);
79+
bytes.push_back(byte);
80+
}
81+
std::string bb(bytes.begin(),bytes.end());
82+
return bb;
83+
}
84+
6985

7086
/**
7187
* \brief Convers the given byte array of the given length to a corresponding binary number in a string.

0 commit comments

Comments
 (0)