Skip to content

Commit a8a1224

Browse files
committed
Updated readme
1 parent ec1f631 commit a8a1224

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

README.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,57 @@
1-
# ByteConvert_cpp
2-
Library for C++ to convert variables to bytes and back
1+
# ByteConvert
2+
[![Build Status](https://travis-ci.org/SloCompTech/ByteConvert_cpp.svg?branch=master)](https://travis-ci.org/SloCompTech/ByteConvert_cpp)
3+
[![Packagist](https://img.shields.io/packagist/l/doctrine/orm.svg)]()
4+
5+
## What's about ?
6+
Have you ever wanted to transmit `int`,`short`,`long`,`double` or any other numeric type over I2C,SPI,serial or other protocol or bus, but you converted variable to string to be able to transmit it char by char. This library enables you to convert any numeric value to bytes or other way around and you can also print array of bytes.
7+
8+
## What you need to consider, when you are using this library
9+
When you are using this library, you need to consider variable byte size, because if you are using different platforms, then there may be some errors, because int on platform 1 has 4 bytes and int on platform 2 may has 2 bytes.
10+
11+
## Examples
12+
Convert numeric variable for eg. `int`,`short`,`float`,`double` to array of bytes.
13+
``` c++
14+
int somevar = 5;
15+
size_t blk_size = 0;
16+
uint8_t *block = ByteConvert::varToArray<int>(blk_size,somevar);
17+
18+
// Use array
19+
20+
delete block; // Don't forget to free memory, when you don't need array any more
21+
```
22+
23+
Convert array of bytes to numeric variable.
24+
``` c++
25+
uint8_t *block; // Predefined byte array with size of int
26+
int somevar = ByteConvert::arrayToVar<int>(block);
27+
28+
// Use block & somevar
29+
30+
delete block; // Don't forget to free memory, when you don't need array any more
31+
32+
// Use somevar
33+
```
34+
35+
Convert array of bytes to string of hex characters
36+
``` c++
37+
size_t blk_size; // Predefined size of byte array
38+
uint8_t *block; // Predefined byte array with size of int
39+
String somevar = ByteConvert::arrayToString(blk_size,block);
40+
41+
// Use block & somevar
42+
43+
delete block; // Don't forget to free memory, when you don't need array any more
44+
45+
// Use somevar
46+
```
47+
48+
Convert string of hex characters to array of bytes
49+
``` c++
50+
String somevar = ""; // Predefined string
51+
size_t blk_size = 0;
52+
uint8_t *block = ByteConvert::stringToArray(blk_size,somevar);
53+
54+
// Use block
55+
56+
delete block; // Don't forget to free memory, when you don't need array any more
57+
```

0 commit comments

Comments
 (0)