- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
unsigned char ToChar(const char& c1, const char& c2)
{
static map<char,int> mapping;
mapping['0'] = 0;
mapping['1'] = 1;
mapping['2'] = 2;
mapping['3'] = 3;
mapping['4'] = 4;
mapping['5'] = 5;
mapping['6'] = 6;
mapping['7'] = 7;
mapping['8'] = 8;
mapping['9'] = 9;
mapping['A'] = 10;
mapping['B'] = 11;
mapping['C'] = 12;
mapping['D'] = 13;
mapping['E'] = 14;
mapping['F'] = 15;
return (unsigned char)(mapping[c2] + mapping[c1] * 16);
}
int main()
{
// Assuming "vector<unsigned char> content" stores the data in Hex format, one Hex character per cell.
for(size_t i=0, j=0; i < content.size(); i+=2, j++)
{
content[j] = ToChar(content[i], content[i+1]); // one unsigned char => 2 Hex characters
}
}
Индусы на СО. Я даже не знаю, что тут самое нелепое.
http://stackoverflow.com/a/24470147/2489083