View Single Post
Join Date: Dec 2008
Posts: 17
Reputation: Egypt Pharaoh is an unknown quantity at this point 
Solved Threads: 0
Egypt Pharaoh Egypt Pharaoh is offline Offline
Newbie Poster

Re: decimal to hexadecimal

 
0
  #2
Dec 25th, 2008
there is the code I have but I don't know if it was right or wrong from "decimal to hexadecimal"
  1. namespace ConsoleApplication2
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7.  
  8. Console.WriteLine("Enter the number that you want to convert to Hexadecimal ");
  9. int n = int.Parse(Console.ReadLine());
  10.  
  11. Console.Write("{0}=",n);
  12. ToHexadecimal(n);
  13. Console.ReadKey();
  14.  
  15. }
  16. static void ToHexadecimal(int n)
  17. {
  18. if (n == 0)
  19. return;
  20. else
  21. {
  22. int r = n % 16;
  23. n =n/ 16;
  24. ToHexadecimal(n);
  25.  
  26.  
  27. switch (r)
  28. {
  29. case 10:
  30. Console.Write("A");
  31. break;
  32. case 11:
  33. Console.Write("B");
  34. break;
  35. case 12:
  36. Console.Write("C");
  37. break;
  38. case 13:
  39. Console.Write("D");
  40. break;
  41. case 14:
  42. Console.Write("E");
  43. break;
  44. case 15:
  45. Console.Write("F");
  46. break;
  47. default:
  48. Console.Write(r);
  49. break;
  50.  
  51. }
  52.  
  53. }
  54. }
  55.  
  56. }
  57. }
Reply With Quote