From dfc1cc97ccc6d92ae5eddf54d3703cc041cd8e89 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sat, 21 Mar 2015 21:28:26 +0100 Subject: [PATCH] Added function to compute parity. --- include/MUtils/Global.h | 3 +++ src/Global.cpp | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/MUtils/Global.h b/include/MUtils/Global.h index c67e050..bc5a438 100644 --- a/include/MUtils/Global.h +++ b/include/MUtils/Global.h @@ -84,6 +84,9 @@ namespace MUtils MUTILS_API quint32 next_rand32(void); MUTILS_API quint64 next_rand64(void); + //Parity + MUTILS_API bool parity(quint32 value); + //Remove File/Dir MUTILS_API bool remove_file(const QString &fileName); MUTILS_API bool remove_directory(const QString &folderPath, const bool &recursive); diff --git a/src/Global.cpp b/src/Global.cpp index 684bcc2..42d2189 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -110,6 +110,23 @@ QString MUtils::rand_str(const bool &bLong) } /////////////////////////////////////////////////////////////////////////////// +// COMPUTE PARITY +/////////////////////////////////////////////////////////////////////////////// + +/* + * Compute parity in parallel + * http://www.graphics.stanford.edu/~seander/bithacks.html#ParityParallel + */ +bool MUtils::parity(quint32 value) +{ + value ^= value >> 16; + value ^= value >> 8; + value ^= value >> 4; + value &= 0xf; + return ((0x6996 >> value) & 1) != 0; +} + +/////////////////////////////////////////////////////////////////////////////// // TEMP FOLDER /////////////////////////////////////////////////////////////////////////////// -- 2.11.4.GIT