-
Notifications
You must be signed in to change notification settings - Fork 10
/
hexlib.cxx
48 lines (40 loc) · 937 Bytes
/
hexlib.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* useful hex manipulation routines
* Copyright Qualcomm Inc 1997
* Adapted for tivodecode-ng
* See COPYING.md for license terms
*/
#include <cctype>
#include <iostream>
#include <string>
#include "hexlib.hxx"
const int COLS = 16;
void hexbulk(uint8_t *buf, int n)
{
int i = 0;
while (i < n)
{
int j = 0;
char ch;
char hexdigit[5];
std::string hexstr = "";
std::string strstr = "";
for (j = 0; (j < COLS) && (i < n); j++, i++)
{
ch = buf[i];
if (std::isspace(ch))
ch = ' ';
else if (!std::isprint(ch))
ch = '.';
std::sprintf(hexdigit, "%02x ", buf[i]);
hexstr += hexdigit;
strstr += ch;
}
while (j < COLS)
{
hexstr += " ";
j++;
}
std::cerr << hexstr << " " << strstr << "\n";
}
}