Supermodel/Src/Util/ByteSwap.cpp

28 lines
606 B
C++
Raw Normal View History

2016-08-10 03:27:59 +00:00
#include "Util/ByteSwap.h"
namespace Util
{
void FlipEndian16(uint8_t *buffer, size_t size)
2016-08-10 03:27:59 +00:00
{
for (size_t i = 0; i < (size & ~1); i += 2)
{
uint8_t tmp = buffer[i + 0];
2016-08-10 03:27:59 +00:00
buffer[i + 0] = buffer[i + 1];
buffer[i + 1] = tmp;
}
}
void FlipEndian32(uint8_t *buffer, size_t size)
{
for (size_t i = 0; i < (size & ~3); i += 4)
{
uint8_t tmp1 = buffer[i+0];
uint8_t tmp2 = buffer[i+1];
buffer[i+0] = buffer[i+3];
buffer[i+1] = buffer[i+2];
buffer[i+2] = tmp2;
buffer[i+3] = tmp1;
2016-08-10 03:27:59 +00:00
}
}
} // Util