From 443544be4f58f47e6432a2676ff81d8b782ce1b6 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Thu, 2 Jul 2015 15:02:10 -0400 Subject: [PATCH] bitutil.h: Implement endian reversal inline functions --- include/fc/bitutil.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 include/fc/bitutil.hpp diff --git a/include/fc/bitutil.hpp b/include/fc/bitutil.hpp new file mode 100644 index 0000000..4d6c3ab --- /dev/null +++ b/include/fc/bitutil.hpp @@ -0,0 +1,28 @@ +#pragma once +#include + +namespace fc { + +inline uint64_t endian_reverse_u64( uint64_t x ) +{ + return (((x >> 0x38) & 0xFF) ) + | (((x >> 0x30) & 0xFF) << 0x08) + | (((x >> 0x28) & 0xFF) << 0x10) + | (((x >> 0x20) & 0xFF) << 0x18) + | (((x >> 0x18) & 0xFF) << 0x20) + | (((x >> 0x10) & 0xFF) << 0x28) + | (((x >> 0x08) & 0xFF) << 0x30) + | (((x ) & 0xFF) << 0x38) + ; +} + +inline uint32_t endian_reverse_u32( uint32_t x ) +{ + return (((x >> 0x18) & 0xFF) ) + | (((x >> 0x10) & 0xFF) << 0x08) + | (((x >> 0x08) & 0xFF) << 0x10) + | (((x ) & 0xFF) << 0x18) + ; +} + +} // namespace fc