Advertisement
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;
- using System.Threading.Tasks;
- namespace Test
- {
- class Program
- {
- static void Main(string[] args)
- {
- while (true)
- {
- Console.WriteLine(@"{1} Convert Decimal to Binary.
- {2} Convert Decimal to Hexadecimal.
- {3} Convert Binary to Decimal.
- {4} Convert Binary to Hexadecimal.
- {5} Convert Hexadecimal to Decimal.
- {6} Convert Hexadecimal to Binary.
- {9} Exit." + "\r\n");
- string input = Console.ReadLine();
- int answer;
- bool checkInput = int.TryParse(input, out answer);
- if (answer == 1)
- {
- //Convert 1234d to binary
- Console.Write("Decimal: ");
- string inputDB = Console.ReadLine();
- int decimBin;
- bool checkinputDB = int.TryParse(inputDB, out decimBin);
- String binN = decimalToBinary(decimBin);
- Console.WriteLine("\r\nBinary Result:");
- Console.WriteLine("{0}", binN.PadLeft(16, '0'));
- Console.WriteLine("{0}", binN);
- }
- }
- }
- private static String decimalToBinary(int decimBin)
- {
- string binN = "";
- while (decimBin > 0)
- {
- int residue = decimBin % 2;
- decimBin /= 2;
- binN = residue + binN;
- }
- return binN;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement