static void Main(string[] args) { var u1_array = new byte[] { 0x01, 0xe8, 0x03 }; var u1 = UBigInt.FromByteArray(u1_array); var r1 = u1.FloorLog10(); // 3が正解 var u2_array = new byte[] { 0x01, 0xff, 0xe3, 0x0b, 0x54, 0x02 }; var u2 = UBigInt.FromByteArray(u2_array); var r2 = u2.FloorLog10(); // 9が正解 Console.ReadLine(); }
static void Main(string[] args) { //var v = UBigInt.FromByteArray(new byte[] { 0x01, 0x01, 0x01 }); //var v = UBigInt.FromByteArray(new byte[] { 0x01, 0x04, 0xd2, 0x02, 0x96, 0x49 }); //var v = UBigInt.FromByteArray(new byte[] { 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01 }); //var v = UBigInt.FromByteArray(new byte[] { 0x01, 0x08, 0xd2, 0x0a, 0x1f, 0xeb, 0x8c, 0xa9, 0x54, 0xab }); //var u = UBigInt.FromByteArray(new byte[] { 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }); //var v = UBigInt.FromByteArray(new byte[] { 0x01, 0x09, 0xff, 0xff, 0x0f, 0x63, 0x2d, 0x5e, 0xc7, 0x6b, 0x05 }); //var v = UBigInt.FromByteArray(new byte[] { 0x01, 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }); //var u = BigInt.FromByteArray(new byte[] { 0x03, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01 }); //var v = 1UL; //var u = 1234567890U; //var u = 4294967295U; //var u = 4294967296UL; //var u = 12345678901234567890UL; var u = UBigInt.FromByteArray(new byte[] { 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }); var v = UBigInt.FromByteArray(new byte[] { 0x01, 0x11, 0xd2, 0x0a, 0x3f, 0xce, 0x96, 0x5f, 0xbc, 0xac, 0xb8, 0xf3, 0xdb, 0xc0, 0x75, 0x20, 0xc9, 0xa0, 0x03 }); var w = u.Multiply(MultiplicationMethod.ToomCook, v); Console.ReadLine(); }
public static IDataItem FromXElement(XElement element) { if (element == null) { return(new NullDataItem()); } var type = element.Attribute("type").Value; var text = element.Value; switch (type) { case "int32": return(new Int32DataItem(Int32.Parse(text))); case "uint32": return(new UInt32DataItem(UInt32.Parse(text))); case "uint64": return(new UInt64DataItem(UInt64.Parse(text))); case "ubigint": { var bytes = text.Split(',').Select(x => byte.Parse(x, NumberStyles.HexNumber)).ToArray(); var p = UBigInt.FromByteArray(bytes); return(new UBigIntDataItem(p)); } case "string": return(new XStringDataItem(text)); case "numberformatinfo": { var dic = text.Split(':') .Where(line => line != "") .Select(line => line.Split('=')) .Select(columns => { if (columns.Length != 2) { throw new ApplicationException(); } var key = columns[0]; var value = columns[1].Replace(":", ":").Replace("=", "=").Replace("&", "&"); return(new { key, value }); }) .ToDictionary(item => item.key, item => item.value); var culture = dic.ContainsKey("CultureName") ? CultureInfo.CreateSpecificCulture(dic["CultureName"]) : CultureInfo.InvariantCulture; foreach (var key_value in dic) { switch (key_value.Key) { case "CurrencyDecimalDigits": culture.NumberFormat.CurrencyDecimalDigits = int.Parse(key_value.Value); break; case "CurrencyDecimalSeparator": culture.NumberFormat.CurrencyDecimalSeparator = key_value.Value; break; case "CurrencyGroupSeparator": culture.NumberFormat.CurrencyGroupSeparator = key_value.Value; break; case "CurrencyGroupSizes": culture.NumberFormat.CurrencyGroupSizes = key_value.Value.Select(c => c - '0').ToArray(); break; case "CurrencyNegativePattern": culture.NumberFormat.CurrencyNegativePattern = int.Parse(key_value.Value); break; case "CurrencyPositivePattern": culture.NumberFormat.CurrencyPositivePattern = int.Parse(key_value.Value); break; case "CurrencySymbol": culture.NumberFormat.CurrencySymbol = key_value.Value; break; case "NegativeSign": culture.NumberFormat.NegativeSign = key_value.Value; break; case "NumberDecimalDigits": culture.NumberFormat.NumberDecimalDigits = int.Parse(key_value.Value); break; case "NumberDecimalSeparator": culture.NumberFormat.NumberDecimalSeparator = key_value.Value; break; case "NumberGroupSeparator": culture.NumberFormat.NumberGroupSeparator = key_value.Value; break; case "NumberGroupSizes": culture.NumberFormat.NumberGroupSizes = key_value.Value.Select(c => c - '0').ToArray(); break; case "NumberNegativePattern": culture.NumberFormat.NumberNegativePattern = int.Parse(key_value.Value); break; case "PercentDecimalDigits": culture.NumberFormat.PercentDecimalDigits = int.Parse(key_value.Value); break; case "PercentDecimalSeparator": culture.NumberFormat.PercentDecimalSeparator = key_value.Value; break; case "PercentGroupSeparator": culture.NumberFormat.PercentGroupSeparator = key_value.Value; break; case "PercentGroupSizes": culture.NumberFormat.PercentGroupSizes = key_value.Value.Select(c => c - '0').ToArray(); break; case "PercentNegativePattern": culture.NumberFormat.PercentNegativePattern = int.Parse(key_value.Value); break; case "PercentPositivePattern": culture.NumberFormat.PercentPositivePattern = int.Parse(key_value.Value); break; case "PercentSymbol": culture.NumberFormat.PercentSymbol = key_value.Value; break; case "PerMilleSymbol": culture.NumberFormat.PerMilleSymbol = key_value.Value; break; case "PositiveSign": culture.NumberFormat.PositiveSign = key_value.Value; break; } } return(new NumberFormatInfoDataItem(text, culture.NumberFormat)); } case "exception": switch (text.ToLower()) { case "overflowexception": return(new ExceptionDataItem(typeof(OverflowException))); case "argumentexception": return(new ExceptionDataItem(typeof(ArgumentException))); case "argumentnullexception": return(new ExceptionDataItem(typeof(ArgumentNullException))); case "formatexception": return(new ExceptionDataItem(typeof(FormatException))); case "dividebyzeroexception": return(new ExceptionDataItem(typeof(DivideByZeroException))); case "arithmeticexception": return(new ExceptionDataItem(typeof(ArithmeticException))); default: throw new ApplicationException(); } default: throw new ApplicationException(); } }