diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-03-13 06:26:06 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | 5a8727e34b938b70623ca865273fd81c7604b461 (patch) | |
tree | a2921e90aa454072dc58fced36b508f67f5d1226 /include/odhtdb/bin2hex.hpp | |
parent | 9ffc25c9d99fe86d4789108d1d8615ecb0388cc6 (diff) |
Expose include dir
Diffstat (limited to 'include/odhtdb/bin2hex.hpp')
-rw-r--r-- | include/odhtdb/bin2hex.hpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/odhtdb/bin2hex.hpp b/include/odhtdb/bin2hex.hpp new file mode 100644 index 0000000..72b57c1 --- /dev/null +++ b/include/odhtdb/bin2hex.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include <string> + +namespace odhtdb +{ + static const char HEX_TABLE[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + + static std::string bin2hex(const char *data, size_t dataSize) + { + std::string result; + result.resize(dataSize * 2); + + for(int i = 0; i < dataSize; ++i) + { + char c = data[i]; + result[i * 2 + 0] = HEX_TABLE[(c & 0xF0) >> 4]; + result[i * 2 + 1] = HEX_TABLE[(c & 0x0F)]; + } + + return result; + } +} |