예제 #1
0
        public string ConvertFromBaseTenToStart(long numberToConvert, string numberSystem)
        {
            int  NumberOfDigitsNeeded = 0;
            int  NumberSystemAsInt    = int.Parse(numberSystem);
            long numberCopy           = numberToConvert;
            ConvertIntArrayToBaseAnythingDigitArray helper = new ConvertIntArrayToBaseAnythingDigitArray();


            while (numberCopy >= 1)
            {
                NumberOfDigitsNeeded++;
                numberCopy /= NumberSystemAsInt;
            }

            int[] digitsBeforeConversion = new int[NumberOfDigitsNeeded];
            numberCopy = numberToConvert;

            for (int i = 0; i < NumberOfDigitsNeeded; i++)
            {
                while (numberCopy >= Math.Pow(NumberSystemAsInt, NumberOfDigitsNeeded - i - 1))
                {
                    digitsBeforeConversion[i]++;
                    numberCopy -= (long)Math.Pow(NumberSystemAsInt, NumberOfDigitsNeeded - i - 1);
                }
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < NumberOfDigitsNeeded; i++)
            {
                sb.Append(helper.ServiceMethod(digitsBeforeConversion[i]));
            }

            return(sb.ToString());
        }
 public void TestAEqualsTen()
 {
     Assert.AreEqual("A", helper.ServiceMethod(10));
 }