Guest User

Untitled

a guest
May 21st, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace P5.ConvertHexadecimalToBinary
  7. {
  8.     class Program
  9.     {
  10.         private static string[] binaryNumbers =
  11.         {
  12.             "0000","0001","0010","0011",
  13.             "0100","0101","0110","0111",
  14.             "1000","1001","1010","1011",
  15.             "1100","1101","1110","1111",                      
  16.         };
  17.         private static string hexNumbers = "0123456789ABCDEF";
  18.         static void Main(string[] args)
  19.         {
  20.             Console.Write("Enter the hex number -> ");
  21.             string numberInHex = Console.ReadLine().ToUpper();
  22.             Console.WriteLine("The binary representation is ->" + ConvertHexadecimalNumberToBinaryNumber(numberInHex));
  23.         }
  24.  
  25.         private static string ConvertHexadecimalNumberToBinaryNumber(string pHexNumber)
  26.         {
  27.             StringBuilder sb = new StringBuilder();
  28.             for (int i = 0; i < pHexNumber.Length; i++)
  29.             {              
  30.                 sb.Append(binaryNumbers[hexNumbers.IndexOf(pHexNumber[i])]);
  31.             }
  32.             return sb.ToString();
  33.         }
  34.     }
  35. }
Add Comment
Please, Sign In to add comment