50
/ 55
IQ21 functions:
public double IQ21toFloat(double Var)
{
if (Var > 2147483648) //if the value is bigger than 2^31 (positive)
{
Var = Var - 4294967296;
// Var - 2^32
Var = Var / (2097152);
// Var / (2^21)
}
else
{
Var = Var / (2097152);
//Var/(2^21)
}
return Var;
}
public UInt32 FloatToIQ21(double Var)
{
UInt32 Retorn = 0;
if (Var < 0)
// if negative
{
Var = (2097152 * Var) + 4294967296; // Var*2^21 + 2^32
}
else
{
Var = Var * (2097152);
// Var*2^21
}
Retorn = Convert.ToUInt32(Var);
return Retorn;
}