public static bool CheckIdentifier(ulong id) { if (id > 0xf4a0eL) { byte minDigits = 11; var buffer = NumbersHelper.SplitNumber(id, minDigits); var num = ((((((((9 * buffer[0]) + (8 * buffer[1])) + (7 * buffer[2])) + (6 * buffer[3])) + (5 * buffer[4])) + (4 * buffer[5])) + (3 * buffer[6])) + (2 * buffer[7])) + buffer[8]; while (num > 0x65) { num = num % 0x65; } switch (num) { case 100: case 0x65: num = 0; break; } if (num != ((10 * buffer[9]) + buffer[10])) { return(false); } } return(true); }
public void SetVolume(Context context, Result result) { var number = result.Entities.OfType(Sys.Text).Value; VolumeHelper.Set((int)NumbersHelper.ParseNumber(number)); result.SendResponse($"как вам угодно"); }
public void TurnOn(Context context, Result result) { var numbers = result.Entities.AllOfType(Sys.Text); if (numbers.Count < 2) { result.SendResponse("Повторите пожалуйста!"); } var firstNum = NumbersHelper.ParseNumber(numbers[0].Value); var secondNum = NumbersHelper.ParseNumber(numbers[1].Value); var operation = result.Entities.OfType("operation").Value; switch (operation) { case "плюс": result.SendResponse((firstNum + secondNum).ToString()); return; case "умножить на": result.SendResponse((firstNum * secondNum).ToString()); return; case "делить на": result.SendResponse((( double )firstNum / secondNum).ToString()); return; case "минус": result.SendResponse((firstNum - secondNum).ToString()); return; } }
public int SearchFor(int number) { for (var current = number - 1; current > 1; current--) { if (NumbersHelper.IsPrime(current)) { return(current); } } return(0); }
/// <summary> /// The calculate check sum. /// </summary> /// <param name="proId"> /// The pro_id. /// </param> /// <param name="hasCheckPosition"> /// The has check position. /// </param> /// <returns> /// The <see cref="byte"/>. /// </returns> public static byte CalculateCheckSum(TStringHelper.ReadonlyString proId, bool hasCheckPosition = false) { var length = proId.Length; if (hasCheckPosition) { length--; } if (length < 2) { throw new ArgumentException("слишком короткий идентификатор"); } var builder = new StringBuilder(); var s = new StringBuilder(); for (var flag = true; length > 0; flag = !flag) { var ch = proId[--length]; if (flag) { builder.Append(ch); } else { s.Append(ch); } } s.Append((Convert.ToUInt64(builder.ToString()) * 2L).ToString(CultureInfo.InvariantCulture)); ulong num2 = 0L; length = s.Length; while (length > 0) { num2 += NumbersHelper.GetDecimalDigitValue(s, --length); } num2 = num2 % 10L; if (num2 > 0L) { num2 = 10L - num2; } return((byte)num2); }
/// <summary> /// The check identifier. /// </summary> /// <param name="id"> /// The id. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public static bool CheckIdentifier(string id) { if (id == null) { return(false); } var length = id.Length; if (length != FullLength) { return(false); } var decimalDigitValue = NumbersHelper.GetDecimalDigitValue(id, length - 1); return(CalculateCheckSum(id, true) == decimalDigitValue); }
/// <summary> /// The region as string. /// </summary> /// <param name="region"> /// The region. /// </param> /// <param name="coding"> /// The coding. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string RegionAsString(ulong region, RegionCoding coding) { return(NumbersHelper.NumberToString(region, RetrieveFullLength(coding))); }
public static bool CheckIdentifier(ulong id) { return(CheckIdentifier(NumbersHelper.NumberToString(id, FullLength))); }