Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3.  
  4. namespace Auxilio
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. do
  11. {
  12. Stack quociente;
  13. int.TryParse(Console.ReadLine(), out int numeroDecimal);
  14. GetQuocientesHex(out quociente, numeroDecimal);
  15. string oh;
  16. TransformToHex(quociente, out oh);
  17. Console.WriteLine(oh);
  18. Console.WriteLine("1 to continue...");
  19. } while (Console.ReadLine().Equals("1"));
  20.  
  21.  
  22. }
  23.  
  24. public static void TransformToHex(Stack stack, out string numberT)
  25. {
  26. numberT = "";
  27. foreach(object o in stack)
  28. {
  29. int number = (int)o;
  30. if(MaiorDez(number))
  31. {
  32. numberT += HexToDec(number);
  33. } else
  34. {
  35. numberT += number.ToString();
  36. }
  37. }
  38. }
  39.  
  40. public static void GetQuocientesHex(out Stack stack, int dec)
  41. {
  42. stack = new Stack();
  43.  
  44. int r = dec / 16; // 70
  45. int q = dec % 16; // 8
  46.  
  47. do
  48. {
  49. stack.Push(q); // 4 6 8
  50. q = r % 16; //
  51. r /= 16; // 0
  52.  
  53. } while (r != 0);
  54. stack.Push(q);
  55.  
  56. }
  57.  
  58. public static bool MaiorDez(int a)
  59. {
  60. return a >= 10;
  61. }
  62.  
  63. public static char HexToDec(int dec)
  64. {
  65. // ASCII A == 65 -> true
  66. return (char)(65 + (dec - 10));
  67.  
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement