-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintHex.cpp
More file actions
29 lines (25 loc) · 853 Bytes
/
Copy pathprintHex.cpp
File metadata and controls
29 lines (25 loc) · 853 Bytes
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
#include "printHex.hpp"
#include "Segments.hpp"
#include "Segment.hpp"
#include <iostream>
#include <iomanip>
#include <sstream>
void printHex(const Segment& segment, std::ostream& stream) {
for (int i = segment.base(); i < segment.base() + segment.size(); ) {
stream << std::hex << std::setw(4) << std::setfill('0') << i << ": ";
for (int j = 0; j < 8 && i < segment.base() + segment.size(); ++j, ++i) {
stream << std::hex << std::setw(2) << std::setfill('0') << (int)segment.get(i) << " ";
}
stream << std::endl;
}
}
void printHex(const Segments& segments, std::ostream& stream) {
for (int i = 0; i < segments.numberOfSegments(); ++i) {
printHex(segments.index(i), stream);
}
}
std::string asHexString(const Segments& segments) {
std::stringstream stream;
printHex(segments, stream);
return stream.str();
}