1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
}
}
|