20 lines
436 B
C
20 lines
436 B
C
|
#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);
|
||
|
}
|
||
|
}
|