Skip to content

Library for C++ to convert variables to bytes and back

License

Notifications You must be signed in to change notification settings

SloCompTech/ByteConvert_cpp

Repository files navigation

Byteconvert

ByteConvert

Build Status Packagist

What's about ?

Have you ever wanted to transmit int,short,long 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.

What you need to consider, when you are using this library

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.

What you need to install this project ?

You need python3, ninja and meson.

sudo apt-get install python3 python3-pip ninja-build
sudo pip3 install meson

Installing

meson build
ninja -C build
ninja -C build test
ninja -C build install

# Or simply
make
sudo make install

If you have problems, that library can't be found run sudo ldconfig /usr/local/lib/x86_64-linux-gnu/ if you haven't changed prefix, else modify path.

How to include library to your c or c++ project ?

It's simple. At the top of your source file include library:

#include <ByteConvert/ByteConvert.hpp>

And when you compile add flag -lbyteconvert, example g++ -std=c++11 MyProject.cpp -lbyteconvert -o MyProject.

Examples

See examples folder