Org.BouncyCastle.Math.BigInteger.Divide C# (CSharp) Method

Divide() public method

public Divide ( BigInteger val ) : BigInteger
val BigInteger
return BigInteger
		public BigInteger Divide(
			BigInteger val)
		{
			if (val.sign == 0)
				throw new ArithmeticException("Division by zero error");

			if (sign == 0)
				return Zero;

			if (val.QuickPow2Check()) // val is power of two
			{
				BigInteger result = this.Abs().ShiftRight(val.Abs().BitLength - 1);
				return val.sign == this.sign ? result : result.Negate();
			}

			int[] mag = (int[]) this.magnitude.Clone();

			return new BigInteger(this.sign * val.sign, Divide(mag, val.magnitude), true);
		}

Same methods

BigInteger::Divide ( int x, int y ) : int[]

Usage Example

Example #1
0
        public static string ByteArrayToBase58(byte[] ba)
        {
            Org.BouncyCastle.Math.BigInteger addrremain = new Org.BouncyCastle.Math.BigInteger(1, ba);

            Org.BouncyCastle.Math.BigInteger big0  = new Org.BouncyCastle.Math.BigInteger("0");
            Org.BouncyCastle.Math.BigInteger big58 = new Org.BouncyCastle.Math.BigInteger("58");

            string b58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

            string rv = "";

            while (addrremain.CompareTo(big0) > 0)
            {
                int d = Convert.ToInt32(addrremain.Mod(big58).ToString());
                addrremain = addrremain.Divide(big58);
                rv         = b58.Substring(d, 1) + rv;
            }

            // handle leading zeroes
            foreach (byte b in ba)
            {
                if (b != 0)
                {
                    break;
                }
                rv = "1" + rv;
            }
            return(rv);
        }
All Usage Examples Of Org.BouncyCastle.Math.BigInteger::Divide