Byte swapping utility function

This commit is contained in:
Bart Trzynadlowski 2016-08-10 03:27:59 +00:00
parent 718c237063
commit 037bfc648d
2 changed files with 26 additions and 0 deletions

14
Src/Util/ByteSwap.cpp Normal file
View file

@ -0,0 +1,14 @@
#include "Util/ByteSwap.h"
namespace Util
{
void ByteSwap(uint8_t *buffer, size_t size)
{
for (size_t i = 0; i < (size & ~1); i += 2)
{
uint8_t x = buffer[i + 0];
buffer[i + 0] = buffer[i + 1];
buffer[i + 1] = x;
}
}
} // Util

12
Src/Util/ByteSwap.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef INCLUDED_BYTESWAP_H
#define INCLUDED_BYTESWAP_H
#include <cstddef>
#include <cstdint>
namespace Util
{
void ByteSwap(uint8_t *buffer, size_t size);
} // Util
#endif // INCLUDED_BYTESWAP_H