Advertisement
nmnikolov

16. DecimalToHexadecimal

Jul 1st, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System;
  2.  
  3. class DecimalToHexadecimal
  4. {
  5.     static void Main()
  6.     {
  7.         long n = long.Parse(Console.ReadLine());
  8.         string hex = "";
  9.         do
  10.         {
  11.             switch (n % 16)
  12.             {
  13.                 case 10: hex = "A" + hex; break;
  14.                 case 11: hex = "B" + hex; break;
  15.                 case 12: hex = "C" + hex; break;
  16.                 case 13: hex = "D" + hex; break;
  17.                 case 14: hex = "E" + hex; break;
  18.                 case 15: hex = "F" + hex; break;
  19.                 default: hex = n % 16 + hex; break;
  20.             }
  21.             n = n / 16;          
  22.         } while (n > 0);
  23.         Console.WriteLine(hex);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement