Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace P5.ConvertHexadecimalToBinary
- {
- class Program
- {
- private static string[] binaryNumbers =
- {
- "0000","0001","0010","0011",
- "0100","0101","0110","0111",
- "1000","1001","1010","1011",
- "1100","1101","1110","1111",
- };
- private static string hexNumbers = "0123456789ABCDEF";
- static void Main(string[] args)
- {
- Console.Write("Enter the hex number -> ");
- string numberInHex = Console.ReadLine().ToUpper();
- Console.WriteLine("The binary representation is ->" + ConvertHexadecimalNumberToBinaryNumber(numberInHex));
- }
- private static string ConvertHexadecimalNumberToBinaryNumber(string pHexNumber)
- {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < pHexNumber.Length; i++)
- {
- sb.Append(binaryNumbers[hexNumbers.IndexOf(pHexNumber[i])]);
- }
- return sb.ToString();
- }
- }
- }
Add Comment
Please, Sign In to add comment