Added function to compute parity.

This commit is contained in:
LoRd_MuldeR 2015-03-21 21:28:26 +01:00
parent 6c3049c3dc
commit dfc1cc97cc
2 changed files with 20 additions and 0 deletions

View File

@ -84,6 +84,9 @@ namespace MUtils
MUTILS_API quint32 next_rand32(void); MUTILS_API quint32 next_rand32(void);
MUTILS_API quint64 next_rand64(void); MUTILS_API quint64 next_rand64(void);
//Parity
MUTILS_API bool parity(quint32 value);
//Remove File/Dir //Remove File/Dir
MUTILS_API bool remove_file(const QString &fileName); MUTILS_API bool remove_file(const QString &fileName);
MUTILS_API bool remove_directory(const QString &folderPath, const bool &recursive); MUTILS_API bool remove_directory(const QString &folderPath, const bool &recursive);

View File

@ -109,6 +109,23 @@ QString MUtils::rand_str(const bool &bLong)
return QString("%1%2").arg(rand_str(false), rand_str(false)); return QString("%1%2").arg(rand_str(false), rand_str(false));
} }
///////////////////////////////////////////////////////////////////////////////
// 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 // TEMP FOLDER
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////