-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool_fun.cpp
159 lines (136 loc) · 3.35 KB
/
tool_fun.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//Copyright 2019 Hust
//Author: HYL
//Descriptor:
/*This file include some useful tool fun.
*/
#include <regex>
#include "tool_fun.h"
//Change dec number to hex number
string ChangeDecToHex(int dec_num){
string res;
while(dec_num > 15){
int mod = dec_num % 16;
dec_num /= 16;
res = ox16_tool[mod] + res;
}
res = ox16_tool[dec_num] + res;
int len = res.size();
if(len < 3){
for(int i = 0; i < 3-len; i++)
res = '0' + res;
}
return res;
}
//Change dec number to hex number
string ChangeDecToHexDataArea(int dec_num){
string res;
while(dec_num > 15){
int mod = dec_num % 16;
dec_num /= 16;
res = ox16_tool[mod] + res;
}
res = ox16_tool[dec_num] + res;
int len = res.size();
if(len < 4){
for(int i = 0; i < 4-len; i++)
res = '0' + res;
}
return res;
}
//Change hex number to dec number
int ChangeHexToDec(string hex_str_val){
int res = 0;
for(int i = hex_str_val.size() - 1, j = 0; i >= 0; i--, j++){
char elem = hex_str_val[i];
int val = 0;
if(elem >= 'a' && elem <= 'f'){
val = elem - 'a' + 10;
}
else if(elem >= 'A' && elem <= 'F'){
val = elem - 'A' + 10;
}
else if(elem >= '0' && elem <= '9'){
val = hex_str_val[i] - '0';
}
else if(elem == 'x'){
return res;
}
else {
throw "Error: invaild character in ChangeHexToDec() ";
}
res += val * pow(16, j);
}
return res;
}
//add two string hex value, return string type hex value
string AddTwoStrHex(string str1, string str2){
int maxLen = max(str1.size(), str2.size());
if(str1.size() > str2.size()){
int dif = maxLen - str2.size();
for(int i = 0; i < dif; i++){
str2 = "0" + str2;
}
} else if(str1.size() < str2.size()){
int dif = maxLen - str1.size();
for(int i = 0; i < dif; i++){
str1 = "0" + str1;
}
}
string res;
int index = 0; //for addtional
for(int i = maxLen - 1; i >= 0; i--){
int num1 = ChangeHexToDec(to_string(str1[i]));
int num2 = ChangeHexToDec(to_string(str2[i]));
int add = num1 + num2 + index;
index = 0;
if(add > 15){
index = 1;
add -= 15;
}
res = ox16_tool[add] + res;
}
if(index != 0) res = ox16_tool[index] + res;
return res;
}
//Change str value to dec value.
long long int ChangeStrToDec(string str_src){
if(str_src.size() == 0 ) return 0;
int src_num = str_src.size();
//8 bytes
long long int res = 0;
regex reg_minus("-.*");
//the number is minus
if(regex_match(str_src, reg_minus)){
for(int i = src_num - 1, j = 0; i >= 1; i--, j++){
int value = str_src[i] - '0';
res += value * pow(10, j);
}
res = 0 - res;
}
//the number is positive
else {
for(int i = src_num - 1, j = 0; i >= 0; i--, j++){
int value = str_src[i] - '0';
res += value * pow(10, j);
}
}
return res;
}
vector<string> DealWithFloatTypeData(string float_data, int data_size){
string data = float_data;
vector<string> res;
return res;
}
vector<string> DealWithDoubleTypeData(string double_data, int data_size){
vector<string> res;
return res;
}
void Check(string op1, string op2, string op_type){
// RegManage* reg_manage_obj = RegManage::getInstance();
int op_size;// = reg_manage_obj->HowBigType(op_type);
if(op_size == 1){
}
else if(op_size == 2){ }
else if(op_size == 4){ }
else if(op_size == 8){ }
}