forked from AttorneyOnline/AO2-Client
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhex_functions.cpp
More file actions
Latest commit
83 lines (71 loc) · 1.78 KB
/
Copy pathhex_functions.cpp
File metadata and controls
83 lines (71 loc) · 1.78 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//WELCOME TO THE EXTREMELY GHETTO HEX CONVERSION KLUDGE BECAUSE I COULDNT MAKE ANYTHING ELSE WORK
#include"hex_functions.h"
namespaceomni
{
charhalfword_to_hex_char(unsignedint input)
{
if (input > 127)
return'F';
switch (input)
{
case0:
return'0';
case1:
return'1';
case2:
return'2';
case3:
return'3';
case4:
return'4';
case5:
return'5';
case6:
return'6';
case7:
return'7';
case8:
return'8';
case9:
return'9';
case10:
return'A';
case11:
return'B';
case12:
return'C';
case13:
return'D';
case14:
return'E';
case15:
return'F';
default:
return'F';
}
}
std::string int_to_hex(unsignedint input)
{
if (input > 255)
return"FF";
std::bitset<8> whole_byte(input);
//240 represents 11110000, our needed bitmask
uint8_t left_mask_int = 240;
std::bitset<8> left_mask(left_mask_int);
std::bitset<8> left_halfword((whole_byte & left_mask) >> 4);
//likewise, 15 represents 00001111
uint8_t right_mask_int = 15;
std::bitset<8> right_mask(right_mask_int);
std::bitset<8> right_halfword((whole_byte & right_mask));
unsignedint left = left_halfword.to_ulong();
unsignedint right = right_halfword.to_ulong();
//std::cout << "now have have " << left << " and " << right << '\n';
char a = halfword_to_hex_char(left);
char b = halfword_to_hex_char(right);
std::string left_string(1, a);
std::string right_string(1, b);
std::string final_byte = left_string + right_string;
//std::string final_byte = halfword_to_hex_char(left) + "" + halfword_to_hex_char(right);
return final_byte;
}
} //namespace omni