Advertisement
vencinachev

DecToBin

Oct 12th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Program
  5. {
  6. public static void Dec2Bin(int num)
  7. {
  8. Stack<int> binary = new Stack<int>();
  9. while (num != 0)
  10. {
  11. binary.Push(num % 2);
  12. num /= 2;
  13. }
  14.  
  15. while (binary.Count != 0)
  16. {
  17. Console.Write(binary.Pop());
  18. }
  19. }
  20. public static void Main()
  21. {
  22. Console.Write("Enter number: ");
  23. int num = int.Parse(Console.ReadLine());
  24. Stack<int> binary = new Stack<int>();
  25. while (num != 0)
  26. {
  27. binary.Push(num % 2);
  28. num /= 2;
  29. }
  30.  
  31. while (binary.Count != 0)
  32. {
  33. Console.Write(binary.Pop());
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement