Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Program
- {
- public static void Dec2Hex(int num)
- {
- Stack<int> hex = new Stack<int>();
- while (num != 0)
- {
- hex.Push(num % 16);
- num /= 16;
- }
- while (hex.Count != 0)
- {
- int digit = hex.Pop();
- if (digit < 10)
- {
- Console.Write(digit);
- }
- else
- {
- switch (digit)
- {
- case 10: Console.Write('A'); break;
- case 11: Console.Write('B'); break;
- case 12: Console.Write('C'); break;
- case 13: Console.Write('D'); break;
- case 14: Console.Write('E'); break;
- case 15: Console.Write('F'); break;
- }
- }
- }
- }
- public static void Main()
- {
- Console.Write("Enter number: ");
- int num = int.Parse(Console.ReadLine());
- Stack<int> hex = new Stack<int>();
- while (num != 0)
- {
- hex.Push(num % 16);
- num /= 16;
- }
- while (hex.Count != 0)
- {
- int digit = hex.Pop();
- if (digit < 10)
- {
- Console.Write(digit);
- }
- else
- {
- switch (digit)
- {
- case 10: Console.Write('A'); break;
- case 11: Console.Write('B'); break;
- case 12: Console.Write('C'); break;
- case 13: Console.Write('D'); break;
- case 14: Console.Write('E'); break;
- case 15: Console.Write('F'); break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement