Advertisement
mrAnderson33

перевод систем счисления

Mar 19th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. /* тз:
  2. Считать, как параметры командной строки 2 числа: 1-число
  3. в десятичной системе счисления, 2- новая система счисления. Перевести
  4. число 1 в систему счисления 2 и вывести на консоль. */
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10.  
  11. namespace lab04_c_
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             int num , base_num;
  18.             int.TryParse(args[0], out num);
  19.             int.TryParse(args[1], out base_num);
  20.  
  21.             Console.WriteLine(overtedgorner(num, base_num));
  22.             Console.WriteLine(Convert.ToString((long)num,base_num));
  23.         }
  24.  
  25.         static string overtedgorner(int num, int osn)
  26.     {
  27.         string res = "";
  28.         while(num!=0)
  29.         {
  30.             if(osn < 10) res += num % osn;
  31.             else res+= Convert.ToChar(num % osn + 55);
  32.             num /= osn;
  33.         }
  34.  
  35.         return new string(res.Reverse().ToArray());
  36.     }
  37.     }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement