Esempio n. 1
0
File: Logical.cs Progetto: vic/ioke
        internal static BigInteger and(BigInteger val, BigInteger that)
        {
            if (that.sign == 0 || val.sign == 0) {
                return BigInteger.ZERO;
            }
            if (that.Equals(BigInteger.MINUS_ONE)){
                return val;
            }
            if (val.Equals(BigInteger.MINUS_ONE)) {
                return that;
            }

            if (val.sign > 0) {
                if (that.sign > 0) {
                    return andPositive(val, that);
                } else {
                    return andDiffSigns(val, that);
                }
            } else {
                if (that.sign > 0) {
                    return andDiffSigns(that, val);
                } else if (val.numberLength > that.numberLength) {
                    return andNegative(val, that);
                } else {
                    return andNegative(that, val);
                }
            }
        }
Esempio n. 2
0
File: Logical.cs Progetto: vic/ioke
        internal static BigInteger xor(BigInteger val, BigInteger that)
        {
            if (that.sign == 0) {
                return val;
            }
            if (val.sign == 0) {
                return that;
            }
            if (that.Equals(BigInteger.MINUS_ONE)) {
                return val.not();
            }
            if (val.Equals(BigInteger.MINUS_ONE)) {
                return that.not();
            }

            if (val.sign > 0) {
                if (that.sign > 0) {
                    if (val.numberLength > that.numberLength) {
                        return xorPositive(val, that);
                    } else {
                        return xorPositive(that, val);
                    }
                } else {
                    return xorDiffSigns(val, that);
                }
            } else {
                if (that.sign > 0) {
                    return xorDiffSigns(that, val);
                } else if (that.getFirstNonzeroDigit() > val.getFirstNonzeroDigit()) {
                    return xorNegative(that, val);
                } else {
                    return xorNegative(val, that);
                }
            }
        }
Esempio n. 3
0
File: Logical.cs Progetto: vic/ioke
        internal static BigInteger not(BigInteger val)
        {
            if (val.sign == 0) {
                return BigInteger.MINUS_ONE;
            }
            if (val.Equals(BigInteger.MINUS_ONE)) {
                return BigInteger.ZERO;
            }
            int[] resDigits = new int[val.numberLength + 1];
            int i;

            if (val.sign > 0) {
                // ~val = -val + 1
                if (val.digits[val.numberLength - 1] != -1) {
                    for (i = 0; val.digits[i] == -1; i++) {
                        ;
                    }
                } else {
                    for (i = 0; (i < val.numberLength) && (val.digits[i] == -1); i++) {
                        ;
                    }
                    if (i == val.numberLength) {
                        resDigits[i] = 1;
                        return new BigInteger(-val.sign, i + 1, resDigits);
                    }
                }
                // Here a carry 1 was generated
            } else {// (val.sign < 0)
                // ~val = -val - 1
                for (i = 0; val.digits[i] == 0; i++) {
                    resDigits[i] = -1;
                }
                // Here a borrow -1 was generated
            }
            // Now, the carry/borrow can be absorbed
            resDigits[i] = val.digits[i] + val.sign;
            // Copying the remaining unchanged digit
            for (i++; i < val.numberLength; i++) {
                resDigits[i] = val.digits[i];
            }
            return new BigInteger(-val.sign, i, resDigits);
        }
Esempio n. 4
0
File: Logical.cs Progetto: vic/ioke
        internal static BigInteger andNot(BigInteger val, BigInteger that)
        {
            if (that.sign == 0 ) {
                return val;
            }
            if (val.sign == 0) {
                return BigInteger.ZERO;
            }
            if (val.Equals(BigInteger.MINUS_ONE)) {
                return that.not();
            }
            if (that.Equals(BigInteger.MINUS_ONE)){
                return BigInteger.ZERO;
            }

            //if val == that, return 0

            if (val.sign > 0) {
                if (that.sign > 0) {
                    return andNotPositive(val, that);
                } else {
                    return andNotPositiveNegative(val, that);
                }
            } else {
                if (that.sign > 0) {
                    return andNotNegativePositive(val, that);
                } else  {
                    return andNotNegative(val, that);
                }
            }
        }