Вот частичный пример uint24_t, который вы могли бы портировать на ваши инструменты (я не знаю набор инструментов 'current' arduino)
// Note: compile with -std=c++17 for the using comma list
// or remove these and put the "std::" into code
#include <algorithm>
using std::swap;
#include <iostream>
using std::cout, std::cerr, std::endl, std::hex, std::dec, std::cin; // c++17
#include <string>
using std::string, std::to_string; // c++17
#include <sstream>
using std::stringstream;
class Uint24_t
{
public:
Uint24_t() : data {0,0,0}
{
cout << "\n sizeof(Uint24_t)= " << sizeof(Uint24_t) // reports 3 bytes
<< " bytes, * 8= " << (sizeof(Uint24_t) * 8) << " bits." << endl;
}
Uint24_t(uint32_t initVal) : data {0,0,0}
{
data[0] = static_cast<uint8_t>((initVal >> 0) & 0xff); // lsbyte
data[1] = static_cast<uint8_t>((initVal >> 8) & 0xff); //
data[2] = static_cast<uint8_t>((initVal >> 16) & 0xff); // msbyte
cout << "\n sizeof(Uint24_t)= " << sizeof(Uint24_t) // reports 3 bytes
<< " bytes, * 8= " << (sizeof(Uint24_t) * 8) << " bits." << endl;
}
~Uint24_t() = default;
std::string show() {
stringstream ss;
ss << " show(): "
<< static_cast<char>(data[2]) << "."
<< static_cast<char>(data[1]) << "."
<< static_cast<char>(data[0]);
return ss.str();
}
std::string dump() {
stringstream ss;
ss << " dump(): " << hex
<< static_cast<int>(data[2]) << "."
<< static_cast<int>(data[1]) << "."
<< static_cast<int>(data[0]);
return ss.str();
}
void swap0_2() { swap(data[0], data[2]); }
private:
uint8_t data[3]; // 3 uint8_t 's
};
class T976_t // ctor and dtor compiler provided defaults
{
public:
int operator()() { return exec(); } // functor entry
private: // methods
int exec()
{
Uint24_t u24(('c' << 16) + // msbyte
('b' << 8) +
('a' << 0));
cout << "\n sizeof(u24) = " << sizeof(u24) << " bytes"
<< "\n " << u24.show()
<< "\n " << u24.dump() << std::endl;
u24.swap0_2(); // swapping lsByte and msByte
cout << "\n sizeof(u24) = " << sizeof(u24) << " bytes"
<< "\n " << u24.show()
<< "\n " << u24.dump() << std::endl;
return 0;
}
}; // class T976_t
int main(int , char**) { return T976_t()(); } // call functor
Типичный вывод:
sizeof(Uint24_t)= 3 bytes, * 8= 24 bits.
sizeof(u24) = 3 bytes
show(): c.b.a
dump(): 63.62.61
sizeof(u24) = 3 bytes
show(): a.b.c
dump(): 61.62.63