-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTinyHelper.cpp
More file actions
94 lines (71 loc) · 1.89 KB
/
TinyHelper.cpp
File metadata and controls
94 lines (71 loc) · 1.89 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
84
85
86
87
88
89
90
91
92
93
94
//Helper-functions to convert an int to a displayable char[]
void IntToChar(char *CharBuffer, int Number) //Only works for positive numbers
{
char TempBuffer[32];
char index = 0;
do
{
char Rest = Number % 10;
Number = Number / 10;
TempBuffer[index] = Rest + 0x30;
index++;
}
while (Number > 0);
for (int i = 0; i < index; i++)
{
CharBuffer[i] = TempBuffer[index - i - 1];
}
CharBuffer[index] = '\0';
}
void IntToChar(char *CharBuffer, int Number, char Digits) //Only works for positive numbers, adds leading 0s to numbers
{
char TempBuffer[32];
char index = 0;
do
{
char Rest = Number % 10;
Number = Number / 10;
TempBuffer[index] = Rest + 0x30;
index++;
}
while (Number > 0);
while (index < Digits)
{
TempBuffer[index + 1] = TempBuffer[index];
TempBuffer[index] = 0x30;
index++;
}
for (int i = 0; i < index; i++)
{
CharBuffer[i] = TempBuffer[index - i - 1];
}
CharBuffer[index] = '\0';
}
void CombineChars(char *Destination, char *Source) //Combines two char[]
{
int ArrayIndex = 0;
while(ArrayIndex < 255)
{
if(Destination[ArrayIndex] == '\0') break;
ArrayIndex++;
}
for(int i = 0; i < 255; i++)
{
if(Source[i] == '\0') break;
else Destination[ArrayIndex] = Source[i];
ArrayIndex++;
}
Destination[ArrayIndex] = '\0';
}
void FloatToChar(char *CharBuffer, float Number)
{
float temp = Number * 1000;
int whole = (int)temp / 1000;
int fract = (int)temp % 1000;
char f[8];
IntToChar(CharBuffer, whole);
IntToChar(f, fract);
char dotchar[2] = { '.', '\0' };
CombineChars(CharBuffer, dotchar);
CombineChars(CharBuffer, f);
}