mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 12:09:36 +00:00
Lots of stuff
This commit is contained in:
37
PortabilityLayer/ByteSwap.cpp
Normal file
37
PortabilityLayer/ByteSwap.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "ByteSwap.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace ByteSwap
|
||||
{
|
||||
void BigInt16(int16_t &v)
|
||||
{
|
||||
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
|
||||
const int8_t *asS8 = reinterpret_cast<const int8_t*>(&v);
|
||||
|
||||
v = static_cast<int16_t>((asS8[0] << 8) | asU8[1]);
|
||||
}
|
||||
|
||||
void BigInt32(int32_t &v)
|
||||
{
|
||||
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
|
||||
const int8_t *asS8 = reinterpret_cast<const int8_t*>(&v);
|
||||
|
||||
v = static_cast<int32_t>((asS8[0] << 24) | (asU8[1] << 16) | (asU8[2] << 8) | asU8[3]);
|
||||
}
|
||||
|
||||
void BigUInt16(uint16_t &v)
|
||||
{
|
||||
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
|
||||
|
||||
v = static_cast<uint16_t>((asU8[0] << 8) | asU8[1]);
|
||||
}
|
||||
|
||||
void BigUInt32(uint32_t &v)
|
||||
{
|
||||
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
|
||||
|
||||
v = static_cast<uint32_t>((asU8[0] << 24) | (asU8[1] << 16) | (asU8[2] << 8) | asU8[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user