// Most architectures do not include a 24 bit integer
#ifndef INT24
#define INT24
#pragma pack(push, 1) // This will align all of the data nicely
// Most architectures do not support a 24 bit integer
// so a way to convert 24 bit integer data had to be
// defined. This structure is used for both its
// pointers as well as its native integer conversions.
struct __int24 {
Byte bytes[3];
#if LITTLE_ENDIAN
__int24& operator = (const __int32& integer) {
bytes[0] = (integer & 0x000000ff);
bytes[1] = (integer & 0x0000ff00) >> 8;
bytes[2] = (integer & 0x00ff0000) >> 16;
return *this;
}
operator __int32 () {
__int32 integer = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16);
if (integer & 0x800000)
integer |= ~0xffffff;
return integer;
}
#else
#error endianness not supported
#endif // Endianness
};
#pragma pack(pop) // Restore old alignment
#endif // INT24
1 2 3 4 5 6 7
void* int24_to_int32(int32_t *dest, const int24_t *source, size_t size) {
for (size_t i = 0; i < size; i++)
dest[i] = (int32_t)source[i]; // Operator defined in DataTypes.h
return dest;
}