Advertisement
Guest User

test2

a guest
Mar 2nd, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Test
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. while (true)
  14. {
  15. Console.WriteLine(@"{1} Convert Decimal to Binary.
  16. {2} Convert Decimal to Hexadecimal.
  17. {3} Convert Binary to Decimal.
  18. {4} Convert Binary to Hexadecimal.
  19. {5} Convert Hexadecimal to Decimal.
  20. {6} Convert Hexadecimal to Binary.
  21. {9} Exit." + "\r\n");
  22.  
  23. string input = Console.ReadLine();
  24. int answer;
  25. bool checkInput = int.TryParse(input, out answer);
  26.  
  27. if (answer == 1)
  28. {
  29. //Convert 1234d to binary
  30. Console.Write("Decimal: ");
  31. string inputDB = Console.ReadLine();
  32. int decimBin;
  33. bool checkinputDB = int.TryParse(inputDB, out decimBin);
  34.  
  35. String binN = decimalToBinary(decimBin);
  36.  
  37. Console.WriteLine("\r\nBinary Result:");
  38. Console.WriteLine("{0}", binN.PadLeft(16, '0'));
  39. Console.WriteLine("{0}", binN);
  40. }
  41. }
  42. }
  43.  
  44. private static String decimalToBinary(int decimBin)
  45. {
  46. string binN = "";
  47.  
  48. while (decimBin > 0)
  49. {
  50. int residue = decimBin % 2;
  51. decimBin /= 2;
  52. binN = residue + binN;
  53. }
  54.  
  55. return binN;
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement