Ejemplo n.º 1
0
        /// <summary>
        /// Метод DecimalToBinary осуществляет перевод чисел с десятиричной в двоичную систему исчесления
        /// </summary>
        /// <typeparam name="Type">Входящее десятиричное число</typeparam>
        /// <returns>Возращает двоичное представление десятиричного числа</returns>
        public Int32 DecimalToBinary <Type>(Type type)
        {
            Type modulo;
            BinarySystem <Type> binary = new BinarySystem <Type>();

            try
            {
                while (BooleanFunctions <Type, Int32, Boolean> .Greater(type, 0))
                {
                    modulo = ArithmeticFunctionsExcellent <Type, Int32> .ModuloTwo(type, 2);

                    type = ArithmeticFunctionsExcellent <Type, Int32> .DivideTwo(type, 2);

                    binary.Binary.Add(modulo);
                }
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.InnerException);
            }
            Int32 Back(List <Type> norm)
            {
                Type[] s = new Type[norm.Count()];
                for (Int32 i = norm.Count() - 1; i >= 0; i--)
                {
                    s[norm.Count() - 1 - i] = norm[i];
                }
                return(Convert.ToInt32(String.Join <Type>("", s)));
            }

            return(Back(binary.Binary));
        }
Ejemplo n.º 2
0
 private Int32 Count <Type>(Type num, Int32 seed, Int32 modulo) where Type : struct
 {
     if (BooleanFunctions <Type, Int32, Boolean> .NotEquals(ArithmeticFunctionsExcellent <Type, Int32> .DivideTwo(num, modulo), 0))
     {
         return(Count(ArithmeticFunctionsExcellent <Type, Int32> .DivideTwo(num, modulo), seed++, modulo));
     }
     else
     {
         return(seed);
     }
 }