Advertisement
DJ_Zoning

HexToBin

Mar 23rd, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. class ConvertHexToBin
  4. {
  5.     static void Main()
  6.     {
  7.         string s = Console.ReadLine();
  8.         StringBuilder binRepresent = new StringBuilder();
  9.         for (int i = 0; i < s.Length; i++)
  10.         {
  11.                 switch (s[i])
  12.             {
  13.                 case 'A': binRepresent.Append("1010"); break;
  14.                 case 'B': binRepresent.Append("1011"); break;
  15.                 case 'C': binRepresent.Append("1100"); break;
  16.                 case 'D': binRepresent.Append("1101"); break;
  17.                 case 'E': binRepresent.Append("1110"); break;
  18.                 case 'F': binRepresent.Append("1111"); break;
  19.                 case '1': binRepresent.Append("0001"); break;
  20.                 case '2': binRepresent.Append("0010"); break;
  21.                 case '3': binRepresent.Append("0011"); break;
  22.                 case '4': binRepresent.Append("0100"); break;
  23.                 case '5': binRepresent.Append("0101"); break;
  24.                 case '6': binRepresent.Append("0110"); break;
  25.                 case '7': binRepresent.Append("0111"); break;
  26.                 case '8': binRepresent.Append("1000"); break;
  27.                 case '9': binRepresent.Append("1001"); break;
  28.                 case '0': binRepresent.Append("0000"); break;
  29.                 default:
  30.                     break;
  31.             }
  32.         }
  33.         Console.WriteLine(binRepresent);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement