-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathshared.cpp
More file actions
121 lines (103 loc) · 2.52 KB
/
shared.cpp
File metadata and controls
121 lines (103 loc) · 2.52 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
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
#include <stdint.h>
#include <stdio.h>
#include "shared.h"
void printBinaryuint8_t(uint8_t byte){
uint8_t mask = 0x80; // 1000 0000
//Print out the binary representation of 'byte', no newlines
while(mask > 0){
putchar((byte & mask) ? '1': '0');
mask >>= 1;
}
}
//Print out the binary representation of 'byte2', no newlines
void printBinaryuint16_t(uint16_t byte2){
uint16_t mask = 0x8000; // 1000 0000 0000 0000
uint8_t n = 1; //counter to put a space between every 4 bits
while(mask > 0){
putchar((byte2 & mask) ? '1': '0');
mask >>= 1;
if((n & 0x03) == 0){ // (n & 0x03) is equivelant to (n % 4)
putchar(' ');
}
n++;
}
}
// Prints out the binary representation of the short,
// but prints dots for values < start, and values > end
// Used to show the current flags in a uint16_t
// For example:
// byte2 ----- 10010001 00001101
// start ----- 3
// end ------- 6;
// printed --- "...1000.........", without the quotes and without newline
void printBinaryuint16_tdots(uint16_t byte2, int start, int end){
int i = 0;
while(i < start){
putchar('.');
i++;
}
uint16_t mask = 0x8000;
mask >>= start;
while(i <= end){
putchar((byte2 & mask) ? '1': '0');
mask >>= 1;
i++;
}
while(i <= 15){
putchar('.');
i++;
}
}
const char *strBinaryuint16_tdots(uint16_t byte2, int start, int end){
static char buffer[17];
int i = 0;
while(i < start){
//putchar('.');
buffer[i] = '.';
i++;
}
uint16_t mask = 0x8000;
mask >>= start;
while(i <= end){
//putchar((byte2 & mask) ? '1': '0');
buffer[i] = (byte2 & mask) ? '1' : '0';
mask >>= 1;
i++;
}
while(i <= 15){
//putchar('.');
buffer[i] = '.';
i++;
}
buffer[16] = '\0';
return buffer;
}
const char * strBinaryuint8_t(uint8_t byte){
static char buffer[9];
uint8_t mask = 0x80; // 1000 0000
//Turn the binary representation of 'byte' into a string
int i = 0;
while(mask > 0){
buffer[i] = (byte & mask) ? '1' : '0';
i++;
mask >>= 1;
}
buffer[8] = '\0';
return buffer;
}
void setBackgroundColor(QList<QStandardItem *> *row, QColor color){
for (int i = 0; i < row->length(); ++i) {
row->at(i)->setData(color, Qt::BackgroundColorRole);
}
}
QString getHTMLentity(char c){
QHash<char, QString> htmlEntities;
htmlEntities.insert('<', "<");
htmlEntities.insert('>', ">");
if(htmlEntities.contains(c)){
return htmlEntities.value(c);
}
else{
return QString(c);
}
}