-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.cpp
39 lines (29 loc) · 984 Bytes
/
util.cpp
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
/*
Service Discovery Protocol - Util
@author: Sebastien Soudan <sebastien.soudan@gmail.com>
*/
#include "util.h"
void convertUint32toArray(const uint32_t value, uint8_t byteArray[]) {
byteArray[0] = (uint8_t)((value >> 24) & 0xFF) ;
byteArray[1] = (uint8_t)((value >> 16) & 0xFF) ;
byteArray[2] = (uint8_t)((value >> 8) & 0XFF);
byteArray[3] = (uint8_t)((value & 0XFF));
}
void convertUint16toArray(const uint16_t value, uint8_t byteArray[]) {
byteArray[0] = (uint8_t)((value >> 8) & 0XFF);
byteArray[1] = (uint8_t)((value & 0XFF));
}
uint16_t convertArraytoUint16(const uint8_t byteArray[]) {
uint16_t value;
value = ( (byteArray[0] << 8)
+ (byteArray[1] ) );
return value;
};
uint32_t convertArraytoUint32(const uint8_t byteArray[]) {
uint32_t value;
value = (((uint32_t) byteArray[0] << 24)
+ ((uint32_t) byteArray[1] << 16)
+ ((uint32_t) byteArray[2] << 8)
+ ((uint32_t) byteArray[3] ));
return value;
};