На 8-битниках работает нормально, на Cortex не проверялось, но
из-за невыровненного доступа возможны нюансы.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef __UINT_24_T
#define __UINT_24_T
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
struct uint24_t
{
protected:
unsigned char Byte[3]; // Битовый образ числа
public:
inline uint24_t(); // Конструкторы
inline uint24_t(const unsigned long);
inline operator unsigned long(); // Операторы преобразования
inline uint24_t& operator =(const unsigned long);
};
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
uint24_t::uint24_t()
{
};
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
uint24_t::uint24_t(const unsigned long Value)
{
Byte[0] = (Value >> 0L) & 0xFF;
Byte[1] = (Value >> 8L) & 0xFF;
Byte[2] = (Value >> 16L) & 0xFF;
};
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
uint24_t::operator unsigned long()
{
return (((unsigned long)Byte[2] << 16L) |
((unsigned long)Byte[1] << 8L) | Byte[0]);
};
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
uint24_t& uint24_t::operator =(const unsigned long Value)
{
Byte[0] = (Value >> 0L) & 0xFF;
Byte[1] = (Value >> 8L) & 0xFF;
Byte[2] = (Value >> 16L) & 0xFF;
return *this;
};
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#endif
//------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
- прикольно - Nikolay801_(06.10.2020 16:24)