-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHexConsole.cpp
50 lines (41 loc) · 1.04 KB
/
HexConsole.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
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <string.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include "HexConsole.h"
static int const index = std::ios_base::xalloc();
std::ostream& hexify(std::ostream& stream) {
stream.iword(index) = 1;
return stream;
}
std::ostream& nohexify(std::ostream& stream) {
stream.iword(index) = 0;
return stream;
}
std::ostream& operator<< (std::ostream& os, const WrapperType& t) {
if (os.iword(index))
return os << std::hex << std::setw(8) << std::setfill('0') << t.getm();
else
return os << t.getm();
}
void HexConsole(unsigned long hi)
{
WrapperType my_int{hi};
std::cout << hexify << my_int;
}
uint32_t ASCII2int(std::string & hasc)
{
uint32_t i;
std::string prefix = "0x";
prefix += hasc;
std::istringstream iss( prefix );
iss >> std::hex >> i;
return i;
}