using System; using System.Collections.Specialized; using System.Text.RegularExpressions; namespace DecToBin { class Program { public static void Main(string[] args) { //******************************************************* // DECIMAL TO BINARY CONVERTER (BWHazel) // This code converts an integer number into its // binary counterpart. Feel free to use this code in // your own programs. // // USAGE: // 1. Click the "upload with new input" field // 2. Type a positive integer and click Submit // The largest number the code can accommodate is // 2147483647. //******************************************************* // Read input and pass to BitVector32 instance uint decNum = uint.Parse(Console.ReadLine()); BitVector32 vector = new BitVector32((int)decNum); // Use regular expression to extract binary number from BitVector32 string representation string binNum = Regex.Replace(vector.ToString(), @"BitVector32\{0*(?[01]+)\}", @"${bin}"); // Output decimal and binary values to Console Console.WriteLine("Decimal: {0}", decNum.ToString()); Console.WriteLine("Binary: {0}", binNum); } } }