Not() public method

public Not ( ) : BigInteger
return BigInteger
Example #1
0
		public BigInteger And(
			BigInteger value)
		{
			if (this.sign == 0 || value.sign == 0)
			{
				return Zero;
			}

			int[] aMag = this.sign > 0
				? this.magnitude
				: Add(One).magnitude;

			int[] bMag = value.sign > 0
				? value.magnitude
				: value.Add(One).magnitude;

			bool resultNeg = sign < 0 && value.sign < 0;
			int resultLength = System.Math.Max(aMag.Length, bMag.Length);
			int[] resultMag = new int[resultLength];

			int aStart = resultMag.Length - aMag.Length;
			int bStart = resultMag.Length - bMag.Length;

			for (int i = 0; i < resultMag.Length; ++i)
			{
				int aWord = i >= aStart ? aMag[i - aStart] : 0;
				int bWord = i >= bStart ? bMag[i - bStart] : 0;

				if (this.sign < 0)
				{
					aWord = ~aWord;
				}

				if (value.sign < 0)
				{
					bWord = ~bWord;
				}

				resultMag[i] = aWord & bWord;

				if (resultNeg)
				{
					resultMag[i] = ~resultMag[i];
				}
			}

			BigInteger result = new BigInteger(1, resultMag, true);

			// TODO Optimise this case
			if (resultNeg)
			{
				result = result.Not();
			}

			return result;
		}
Example #2
0
		public BigInteger AndNot(
			BigInteger val)
		{
			return And(val.Not());
		}
        public IBigInteger Xor(
            IBigInteger value)
        {
            if (this.SignValue == 0)
                return value;

            if (value.SignValue == 0)
                return this;

            int[] aMag = this.SignValue > 0
                             ? this.Magnitude
                             : Add(One).Magnitude;

            int[] bMag = value.SignValue > 0
                             ? value.Magnitude
                             : value.Add(One).Magnitude;

            // TODO Can just replace with sign != value.sign?
            bool resultNeg = (SignValue < 0 && value.SignValue >= 0) || (SignValue >= 0 && value.SignValue < 0);
            int resultLength = System.Math.Max(aMag.Length, bMag.Length);
            var resultMag = new int[resultLength];

            int aStart = resultMag.Length - aMag.Length;
            int bStart = resultMag.Length - bMag.Length;

            for (int i = 0; i < resultMag.Length; ++i)
            {
                int aWord = i >= aStart ? aMag[i - aStart] : 0;
                int bWord = i >= bStart ? bMag[i - bStart] : 0;

                if (this.SignValue < 0)
                {
                    aWord = ~aWord;
                }

                if (value.SignValue < 0)
                {
                    bWord = ~bWord;
                }

                resultMag[i] = aWord ^ bWord;

                if (resultNeg)
                {
                    resultMag[i] = ~resultMag[i];
                }
            }

            IBigInteger result = new BigInteger(1, resultMag, true);

            // TODO Optimise this case
            if (resultNeg)
            {
                result = result.Not();
            }

            return result;
        }