Class5.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using static System.Runtime.InteropServices.JavaScript.JSType;
  7. namespace Library5Class
  8. {
  9. internal class Class5
  10. {
  11. public int decimal10;
  12. public string? decimal16;
  13. public Class5(int decimal10)
  14. {
  15. this.decimal10 = decimal10;
  16. }
  17. public void Result()
  18. {
  19. int ost;
  20. int decimal1 = decimal10;
  21. while (decimal1 > 0)
  22. {
  23. ost = decimal1 % 16;
  24. if (ost < 10)
  25. {
  26. decimal16 += ost;
  27. }
  28. else
  29. {
  30. switch (ost)
  31. {
  32. case 10: decimal16 += 'A'; break;
  33. case 11: decimal16 += 'B'; break;
  34. case 12: decimal16 += 'C'; break;
  35. case 13: decimal16 += 'D'; break;
  36. case 14: decimal16 += 'E'; break;
  37. case 15: decimal16 += 'F'; break;
  38. }
  39. }
  40. decimal1 = decimal1 / 16;
  41. }
  42. char[] mass = decimal16.ToCharArray();
  43. Array.Reverse(mass);
  44. decimal16 = new string(mass);
  45. Console.WriteLine($"{decimal10} (10) = {decimal16} (16)");
  46. }
  47. }
  48. }