Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- class ConvertHexToBin
- {
- static void Main()
- {
- string s = Console.ReadLine();
- StringBuilder binRepresent = new StringBuilder();
- for (int i = 0; i < s.Length; i++)
- {
- switch (s[i])
- {
- case 'A': binRepresent.Append("1010"); break;
- case 'B': binRepresent.Append("1011"); break;
- case 'C': binRepresent.Append("1100"); break;
- case 'D': binRepresent.Append("1101"); break;
- case 'E': binRepresent.Append("1110"); break;
- case 'F': binRepresent.Append("1111"); break;
- case '1': binRepresent.Append("0001"); break;
- case '2': binRepresent.Append("0010"); break;
- case '3': binRepresent.Append("0011"); break;
- case '4': binRepresent.Append("0100"); break;
- case '5': binRepresent.Append("0101"); break;
- case '6': binRepresent.Append("0110"); break;
- case '7': binRepresent.Append("0111"); break;
- case '8': binRepresent.Append("1000"); break;
- case '9': binRepresent.Append("1001"); break;
- case '0': binRepresent.Append("0000"); break;
- default:
- break;
- }
- }
- Console.WriteLine(binRepresent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement