ToString() public method

public ToString ( ) : string
return string
Beispiel #1
0
        /* get plaintext using biginteger class. This is required because default int cannot handle large modpow function */
        public byte[] getMyPlainText(int [] a, int d, int n)
        {
            int l = a.Length;

            byte [] r = new byte[l];

            for (int i = 0; i < a.Length; i++)
            {
                int temp = a[i];

                /* if temp=199 which represents blankspace, handle it differently */
                if (temp == 199 || temp == 200 || temp == 201)
                {
                    r[i] = (byte)temp;
                    continue;
                }

                Mono.Math.BigInteger bi = temp;
                bi = bi.ModPow(d, n);
                string tempString = bi.ToString();
                int    g          = Int32.Parse(tempString);
                r[i] = (byte)g;
            }

            return(r);
        }
		static string ToDecimalString (string hexString)
		{
#if TARGET_DOTNET
			throw new NotImplementedException ();
#else			
            // http://tools.ietf.org/html/rfc5280#section-4.1.2.2
            // We SHOULD support negative numbers
            var bytes = FromBinHex (hexString);
			
            var negative = bytes.Length > 0 && bytes [0] >= 0x80;
            if (negative) {
                for (int i = 0; i < bytes.Length; i++)
                    bytes [i] = (byte) ~ bytes [i];
            }
        	
			var big = new BigInteger (bytes);
			if (negative) { 
				big = big + 1;
				return "-" + big.ToString ();
			} else 
				return big.ToString ();
#endif
        }
        public static int GetTrailingZerosCount(BigInteger num)
        {
            int count = 0;
            string numAsString = num.ToString ();
            int len = numAsString.Length;

            for (int i = 0; i < len; i++)
            {
                int digit = int.Parse (numAsString[len - i - 1].ToString());
                if (digit != 0)
                {
                    break;
                }
                count += 1;
            }

            return count;
        }
Beispiel #4
0
        public static string Convert(string source, int sourceRadix, int targetRadix)
        {
            /* Check if radix arguments are within the allowed range. */
            if (sourceRadix < MIN_RADIX || sourceRadix > MAX_RADIX)
                throw new ArgumentOutOfRangeException("sourceRadix", "Source radix needs to be in a range from " + MIN_RADIX + " to " + MAX_RADIX);
            if (targetRadix < MIN_RADIX || targetRadix > MAX_RADIX)
                throw new ArgumentOutOfRangeException("targetRadix", "Target radix needs to be in a range from " + MIN_RADIX + " to " + MAX_RADIX);

            BigInteger radixFrom = new BigInteger((UInt32)sourceRadix);
            BigInteger value = new BigInteger(0);
            BigInteger multiplier = new BigInteger(1);

            for (int i = source.Length - 1; i >= 0; i--)
            {
                int digit = Digit(source[i], sourceRadix);
                if (digit == -1)
                    throw new ArgumentException("The character '" + source[i] + "' is not defined for the source radix.", "sourceRadix");
                value += multiplier * digit;
                multiplier = multiplier * radixFrom;
            }

            return value.ToString((UInt32)targetRadix, CHARACTERS.Substring(0, targetRadix));
        }