private int calcBitLength(
int indx,
int[] mag)
{
for (;;)
{
if (indx >= mag.Length)
return 0;
if (mag[indx] != 0)
break;
++indx;
}
// bit length for everything after the first int
int bitLength = 32 * ((mag.Length - indx) - 1);
// and determine bitlength of first int
int firstMag = mag[indx];
bitLength += BitLen(firstMag);
// Check for negative powers of two
if (sign < 0 && ((firstMag & -firstMag) == firstMag))
{
do
{
if (++indx >= mag.Length)
{
--bitLength;
break;
}
}
while (mag[indx] == 0);
}
return bitLength;
}