-
Notifications
You must be signed in to change notification settings - Fork 5
/
bytesread.c
61 lines (54 loc) · 1.11 KB
/
bytesread.c
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
#include "bytesread.h"
uint32_t read_2bytes_to_uint32(const uint8_t* data)
{
union byte4uint32 u;
u.b[3] = 0;
u.b[2] = 0;
u.b[1] = *data;
u.b[0] = *(data+1);
return u.i;
}
uint32_t read_3bytes_to_uint32(const uint8_t* data)
{
union byte4uint32 u;
u.b[3] = 0;
u.b[2] = *data;
u.b[1] = *(data+1);
u.b[0] = *(data+2);
return u.i;
}
uint32_t read_4bytes_to_uint32(const uint8_t* data)
{
union byte4uint32 u;
u.b[3] = *data;
u.b[2] = *(data+1);
u.b[1] = *(data+2);
u.b[0] = *(data+3);
return u.i;
}
uint64_t read_8bytes_to_uint64(const uint8_t* data)
{
union byte8uint64 u;
u.b[7] = *data;
u.b[6] = *(data+1);
u.b[5] = *(data+2);
u.b[4] = *(data+3);
u.b[3] = *(data+4);
u.b[2] = *(data+5);
u.b[1] = *(data+6);
u.b[0] = *(data+7);
return u.i;
}
double read_8bytes_to_double(const uint8_t* data)
{
union byte8double u;
u.b[7] = *data;
u.b[6] = *(data+1);
u.b[5] = *(data+2);
u.b[4] = *(data+3);
u.b[3] = *(data+4);
u.b[2] = *(data+5);
u.b[1] = *(data+6);
u.b[0] = *(data+7);
return u.d;
}