Gray lookup table

This commit is contained in:
Jonny007-MKD 2014-01-07 18:05:55 +01:00
parent fcc34a9fa2
commit b77e4e0127
2 changed files with 23 additions and 2 deletions

View file

@ -3,6 +3,10 @@
using namespace std;
extern uint numElements;
uint* Tools::GrayToBinaryTable = NULL;
// convert the binary representation of x to a string with the specified length
char* Tools::BinaryToChars(uint x, char length)
{
@ -20,9 +24,22 @@ char* Tools::BinaryToChars(uint x, char length)
return c;
}
// converts a gray number to its binary representation
// yes, this is quite slow and we could generate a lookup table to speed it up.
uint Tools::GrayToBinary(uint x)
{
if (Tools::GrayToBinaryTable == NULL)
Tools::InitGrayToBinaryTable();
return Tools::GrayToBinaryTable[x];
}
void Tools::InitGrayToBinaryTable()
{
Tools::GrayToBinaryTable = new uint[numElements];
for (uint i = 0; i < numElements; i++)
Tools::GrayToBinaryTable[i] = Tools::CalcGrayToBinary(i);
}
// converts a gray number to its binary representation
uint Tools::CalcGrayToBinary(uint x)
{
uint x1 = x;
char r = 0; // r = ceil(ld(x))

View file

@ -6,4 +6,8 @@ public:
static char* Tools::BinaryToChars(uint x, char length);
static uint GrayToBinary(uint x);
private:
static void InitGrayToBinaryTable();
static uint* GrayToBinaryTable;
static uint Tools::CalcGrayToBinary(uint x);
};