Mono.Math.BigInteger.testBit C# (CSharp) Method

testBit() public method

public testBit ( int bitNum ) : bool
bitNum int
return bool
		public bool testBit (int bitNum)
		{
			if (bitNum < 0) throw new IndexOutOfRangeException ("bitNum out of range");

			uint bytePos = (uint)bitNum >> 5;             // divide by 32
			byte bitPos = (byte)(bitNum & 0x1F);    // get the lowest 5 bits

			uint mask = (uint)1 << bitPos;
			return ((this.data [bytePos] | mask) == this.data [bytePos]);
		}

Same methods

BigInteger::testBit ( uint bitNum ) : bool

Usage Example

Beispiel #1
0
            public BigInteger EvenPow(BigInteger b, BigInteger exp)
            {
                BigInteger resultNum = new BigInteger((BigInteger)1, mod.length << 1);
                BigInteger tempNum = new BigInteger(b % mod, mod.length << 1);  // ensures (tempNum * tempNum) < b^ (2k)

                uint totalBits = (uint)exp.bitCount();

                uint[] wkspace = new uint[mod.length << 1];

                // perform squaring and multiply exponentiation
                for (uint pos = 0; pos < totalBits; pos++)
                {
                    if (exp.testBit(pos))
                    {

                        Array.Clear(wkspace, 0, wkspace.Length);
                        Kernel.Multiply(resultNum.data, 0, resultNum.length, tempNum.data, 0, tempNum.length, wkspace, 0);
                        resultNum.length += tempNum.length;
                        uint[] t = wkspace;
                        wkspace = resultNum.data;
                        resultNum.data = t;

                        BarrettReduction(resultNum);
                    }

                    Kernel.SquarePositive(tempNum, ref wkspace);
                    BarrettReduction(tempNum);

                    if (tempNum == 1)
                    {
                        return resultNum;
                    }
                }

                return resultNum;
            }
All Usage Examples Of Mono.Math.BigInteger::testBit