-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpasmotypes.cpp
65 lines (48 loc) · 1009 Bytes
/
pasmotypes.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// pasmotypes.cpp
// Revision 8-dec-2004
#include "pasmotypes.h"
namespace {
const char hexdigit []= { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
} // namespace
std::string hex2str (byte b)
{
return std::string (1, hexdigit [ (b >> 4) & 0x0F] ) +
hexdigit [b & 0x0F];
}
std::string hex4str (address n)
{
return hex2str (hibyte (n) ) + hex2str (lobyte (n) );
}
std::string hex8str (size_t nn)
{
return hex4str ( (nn >> 16) & 0xFFFF) + hex4str (nn & 0xFFFF);
}
std::string Hex2::str () const
{
return hex2str (b);
}
std::string Hex4::str () const
{
return hex4str (n);
}
std::string Hex8::str () const
{
return hex8str (nn);
}
std::ostream & operator << (std::ostream & os, const Hex2 & h2)
{
os << h2.str ();
return os;
}
std::ostream & operator << (std::ostream & os, const Hex4 & h4)
{
os << h4.str ();
return os;
}
std::ostream & operator << (std::ostream & os, const Hex8 & h8)
{
os << h8.str ();
return os;
}
// End of pasmotypes.cpp