TeaSpeakLibrary/src/misc/hex.h

20 lines
436 B
C
Raw Normal View History

2019-06-26 16:11:22 -04:00
#pragma once
#include <string>
#include <cassert>
namespace hex {
inline std::string hex(const std::string& input, char beg, char end){
assert(end - beg == 16);
int len = input.length() * 2;
char output[len];
int idx = 0;
for (char elm : input) {
output[idx++] = static_cast<char>(beg + ((elm >> 4) & 0x0F));
output[idx++] = static_cast<char>(beg + ((elm & 0x0F) >> 0));
}
return std::string(output, len);
}
}