forked from lupyuen/send_altitude_cocoos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
54 lines (46 loc) · 1.02 KB
/
utils.cpp
File metadata and controls
54 lines (46 loc) · 1.02 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
/*
* utils.cpp
*
* Created on: Sep 1, 2018
* Author: peter
*/
#include "utils.h"
#include <stddef.h>
void uint32ToStringBase16(char buffer[], uint32_t value)
{
size_t length = 0u;
uint32_t tmp = value;
/* Calculate length of resulting string */
while (tmp > 0u)
{
tmp /= 16u;
length++;
}
if (length == 0u)
{
buffer[0] = '0';
buffer[1] = (char)0;
}
else
{
// always set the length to 8 bytes
length = 8;
buffer[length] = (char)0;
while (length > 0u)
{
uint32_t rest = value % 16u;
if (rest < 10u)
{
uint32_t TempVal = 0x30u + rest; /* Needed to pass MISRA */
buffer[length - 1u] = (char)TempVal;
}
else
{
uint32_t TempVal = 0x41u + rest - 10u;
buffer[length - 1u] = (char)(TempVal);
}
value /= 16u;
length--;
}
}
}