Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp17
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. int cislo = 0;
  15. Console.WriteLine("Z jaké soustavy?");
  16. string soustava = Console.ReadLine();
  17. Console.WriteLine("Zadej hodnotu");
  18. string hodnota = Console.ReadLine();
  19. hodnota = hodnota.ToUpper();
  20. Console.WriteLine("Do jaké soustavy?");
  21. string DO = Console.ReadLine();
  22. if (soustava =="HEX")
  23. {
  24. if (DO == "DEC")
  25. {
  26. for (int i = 0; i < hodnota.Length; i++)
  27. {
  28. if ((hodnota[i] >= '0' && hodnota[i] <= '9') || (hodnota[i] >= 'A' && hodnota[i] <= 'F'))
  29. {
  30. cislo = cislo * 16;
  31. if (hodnota[i] >= '0' && hodnota[i] <= '9')
  32. {
  33. cislo += (hodnota[i] - '0');
  34. }
  35. else
  36. {
  37. cislo += (hodnota[i] - 'A') + 10;
  38. }
  39.  
  40. }
  41. }
  42. Console.WriteLine(cislo);
  43. }
  44. else if (DO == "BIN")
  45. {
  46. for (int i = 0; i < hodnota.Length; i++)
  47. {
  48. if ((hodnota[i] >= '0' && hodnota[i] <= '9')
  49. || (hodnota[i] >= 'A' && hodnota[i] <= 'F'))
  50. {
  51. cislo = cislo * 16;
  52. if (hodnota[i] >= '0' && hodnota[i] <= '9')
  53. {
  54. cislo += (hodnota[i] - '0');
  55. }
  56. else
  57. {
  58. cislo += (hodnota[i] - 'A') + 10;
  59. }
  60. }
  61. }
  62. string cislotext = "";
  63. while (cislo != 0)
  64. {
  65. int tmp = cislo % 2;
  66. cislo = cislo / 2;
  67. cislotext += tmp;
  68. }
  69. char[] charArray = cislotext.ToCharArray();
  70. Array.Reverse(charArray);
  71. cislotext = new string(charArray);
  72. Console.WriteLine(cislotext);
  73. Console.ReadLine();
  74. }
  75.  
  76.  
  77.  
  78. }
  79. if (soustava == "DEC")
  80. {
  81. if (DO == "BIN")
  82. {
  83. int cislo = Convert.ToInt32(hodnota);
  84. string cislotext = "";
  85. while (cislo != 0)
  86. {
  87.  
  88. int tmp = cislo % 2;
  89. cislo = cislo / 2;
  90. cislotext += tmp;
  91. }
  92. char[] charArray = cislotext.ToCharArray();
  93. Array.Reverse(charArray);
  94. cislotext = new string(charArray);
  95. Console.WriteLine(cislotext);
  96. Console.ReadLine();
  97.  
  98.  
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. }
  108.  
  109. Console.ReadLine();
  110. }
  111.  
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement