EndianUtils
Add this in your code:
#include <engine/tools/endian_utils.h>
Description
Utility class for endian conversion.
Usefull when using binary data on different platforms.
Static methods
IsBigEndian
Checks if the system is big-endian. For examples PC use little-endian, but PlayStation 3 use big-endian.
bool IsBigEndian()
Code sample:
// True on PlayStation 3
// False on most PC, PSP and PsVita
bool isBigEndian = EndianUtils::IsBigEndian();
SwapEndian
Converts an type from little-endian to big-endian or vice versa.
Only use simple types like int32_t, uint16_t, etc. Do not use this for complex types like structs or classes.
Parameters:
value
: Value to swap endian to
template <typename T>
T SwapEndian(T value)
Code sample:
uint32_t value = 123;
uint32_t newValue = EndianUtils::SwapEndian(value); // = 2063597568