-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathto_variable.cpp
More file actions
29 lines (24 loc) · 776 Bytes
/
to_variable.cpp
File metadata and controls
29 lines (24 loc) · 776 Bytes
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
#include <cstdint>
#include <cstring>
#include <ByteConvert/ByteConvert.cpp>
int main()
{
// Create array of bytes that represent 1 (type: int)
uint8_t block[sizeof(int)];
memset(block,0,sizeof(int)-1);
block[sizeof(int)-1] = 1;
int val = ByteConvert::to_variable<int>(block); // Convert array of bytes to int
if (val != 1) { // Check if we got, what we expected to get
// Error, something went wrong
return -1;
}
// Test with negative values
memset(block,0xff,sizeof(int));
val = ByteConvert::to_variable<int>(block); // Convert array of bytes to int
if (val != -1) { // Check if we got, what we expected to get
// Error, something went wrong
return -2;
}
// Success
return 0;
}