Skip to content

Commit 007f787

Browse files
committed
Add applications.
1 parent 588d75d commit 007f787

15 files changed

+1723
-0
lines changed

DataConverter/DataConverter.pro

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
QT -= gui
2+
3+
CONFIG -= app_bundle
4+
DEFINES += QT_DEPRECATED_WARNINGS
5+
6+
SOURCES += \
7+
main.cpp \
8+
converter.cpp
9+
10+
HEADERS += \
11+
converter.h

DataConverter/DataConverter.pro.user

Lines changed: 323 additions & 0 deletions
Large diffs are not rendered by default.

DataConverter/converter.cpp

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#include "converter.h"
2+
3+
std::string Converter::IntegerToString(int value)
4+
{
5+
std::string conv = std::to_string(value);
6+
7+
return conv;
8+
}
9+
10+
std::string Converter::DoubleToString(double value)
11+
{
12+
std::string conv = std::to_string(value);
13+
14+
return conv;
15+
}
16+
17+
int Converter::StringToInteger(std::string value)
18+
{
19+
int conv = stoi(value);
20+
21+
return conv;
22+
}
23+
24+
double Converter::StringToDouble(std::string value)
25+
{
26+
double conv = stod(value);
27+
28+
return conv;
29+
}
30+
31+
std::string Converter::UnsignedCharToString(unsigned char value)
32+
{
33+
int value_int = (int) value;
34+
std::string conv = std::to_string(value_int);
35+
36+
return conv;
37+
}
38+
39+
std::string Converter::UnsignedCharArrayToString(unsigned char value[], int lenght)
40+
{
41+
std::string conv(value, value + lenght);
42+
43+
return conv;
44+
}
45+
46+
void Converter::DoubleToCharArray(char value_char[], double value)
47+
{
48+
int count = 0;
49+
value = value * 10;
50+
int value_int = (int)value;
51+
52+
while (value_int>0) {
53+
int tmp_value = value_int % 10;
54+
value_char[count] = tmp_value + '0';
55+
value_int = value_int / 10;
56+
count++;
57+
}
58+
}
59+
60+
void Converter::IntToCharArray(char value_char[], int value_int)
61+
{
62+
int count = 0;
63+
while (value_int>0) {
64+
int tmp_value = value_int % 10;
65+
value_char[count] = tmp_value + '0';
66+
value_int = value_int / 10;
67+
count++;
68+
}
69+
}
70+
71+
int Converter::ConvertInteger(double value)
72+
{
73+
int conv = (int) value;
74+
75+
return conv;
76+
}
77+
78+
int Converter::ConvertDecimal(double value)
79+
{
80+
int integer_value_1 = (int) value;
81+
int integer_value_2 = (int) (value * 10);
82+
int conv = integer_value_2 - (integer_value_1 * 10);
83+
84+
return conv;
85+
}
86+
87+
int Converter::HexadecimalToDecimal(char values[])
88+
{
89+
int len = 4;
90+
int base = 1;
91+
int dec_val = 0;
92+
93+
for (int i = len - 1; i >= 0; i--) {
94+
if (values[i] >= '0' && values[i] <= '9') {
95+
dec_val += (values[i] - 48) * base;
96+
base = base * 16;
97+
} else if (values[i] >= 'A' && values[i] <= 'F') {
98+
dec_val += (values[i] - 55) * base;
99+
base = base * 16;
100+
}
101+
}
102+
103+
return dec_val;
104+
}
105+
106+
int Converter::UnsignedChar16BitToInt(unsigned char first, unsigned char second)
107+
{
108+
int result = 0;
109+
int binary_first[8];
110+
int binary_second[8];
111+
112+
for (int i = 0; i < 8; i++) {
113+
binary_first[i] = (first >> i) & 1;
114+
binary_second[i] = (second >> i) & 1;
115+
}
116+
117+
for (int i = 0; i < 8; i++) {
118+
result += binary_first[i] * pow(2, i);
119+
result += binary_second[i] * pow(2, i + 8);
120+
}
121+
122+
return result;
123+
}
124+
125+
int Converter::UnsignedChar32BitToInt(unsigned char first, unsigned char second, unsigned char third, unsigned char four)
126+
{
127+
int result = 0;
128+
int binary_first[8];
129+
int binary_second[8];
130+
int binary_third[8];
131+
int binary_four[8];
132+
133+
for (int i = 0; i < 8; i++) {
134+
binary_first[i] = (first >> i) & 1;
135+
binary_second[i] = (second >> i) & 1;
136+
binary_third[i] = (third >> i) & 1;
137+
binary_four[i] = (four >> i) & 1;
138+
}
139+
140+
141+
for (int i = 0; i < 8; i++) {
142+
result += binary_first[i] * pow(2, i);
143+
result += binary_second[i] * pow(2, i + 8);
144+
result += binary_third[i] * pow(2, i + 16);
145+
result += binary_four[i] * pow(2, i + 24);
146+
}
147+
148+
return result;
149+
}

DataConverter/converter.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef CONVERTER_H
2+
#define CONVERTER_H
3+
4+
#include <string>
5+
#include <math.h>
6+
7+
class Converter
8+
{
9+
public:
10+
std::string IntegerToString(int value);
11+
std::string DoubleToString(double value);
12+
int StringToInteger(std::string value);
13+
double StringToDouble(std::string value);
14+
std::string UnsignedCharToString(unsigned char value);
15+
std::string UnsignedCharArrayToString(unsigned char value[], int lenght);
16+
void DoubleToCharArray(char value_char[], double value);
17+
void IntToCharArray(char value_char[], int value_int);
18+
int ConvertInteger(double value);
19+
int ConvertDecimal(double value);
20+
int HexadecimalToDecimal(char values[]);
21+
int UnsignedChar16BitToInt(unsigned char first, unsigned char second);
22+
int UnsignedChar32BitToInt(unsigned char first, unsigned char second, unsigned char third, unsigned char four);
23+
};
24+
25+
#endif // CONVERTER_H

DataConverter/main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <QCoreApplication>
2+
#include <iostream>
3+
#include "converter.h"
4+
5+
int main(int argc, char *argv[])
6+
{
7+
QCoreApplication a(argc, argv);
8+
9+
Converter converter;
10+
std::cout << "Integer To String (123) -> " << converter.IntegerToString(123) << std::endl;
11+
std::cout << "Double To String (456.87) -> " << converter.DoubleToString(456.87) << std::endl;
12+
std::cout << "String To Integer ('8729') -> " << converter.StringToInteger("8729") << std::endl;
13+
std::cout << "String To Double ('4344.6') -> " << converter.StringToDouble("4344.6") << std::endl;
14+
std::cout << "Unsigned Char To String (201) -> " << converter.UnsignedCharToString(201) << std::endl;
15+
std::cout << "Convert Integer (657.6) -> " << converter.ConvertInteger(657.6) << std::endl;
16+
std::cout << "Convert Decimal (419.4) -> " << converter.ConvertDecimal(419.4) << std::endl;
17+
std::cout << "Unsigned Char 16Bit To Int (2, 8) -> " << converter.UnsignedChar16BitToInt(2, 8) << std::endl;
18+
std::cout << "Unsigned Char 32Bit To Int (5, 5, 9, 7) -> " << converter.UnsignedChar32BitToInt(5, 5, 9, 7) << std::endl;
19+
20+
return a.exec();
21+
}

MOAFilter/MOAFilter.pro

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
QT -= gui
2+
3+
CONFIG -= app_bundle
4+
DEFINES += QT_DEPRECATED_WARNINGS
5+
6+
SOURCES += \
7+
main.cpp

0 commit comments

Comments
 (0)