fork download
  1. using System;
  2. using System.Collections.Specialized;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace DecToBin
  6. {
  7. class Program
  8. {
  9. public static void Main(string[] args)
  10. {
  11. //*******************************************************
  12. // DECIMAL TO BINARY CONVERTER (BWHazel)
  13. // This code converts an integer number into its
  14. // binary counterpart. Feel free to use this code in
  15. // your own programs.
  16. //
  17. // USAGE:
  18. // 1. Click the "upload with new input" field
  19. // 2. Type a positive integer and click Submit
  20. // The largest number the code can accommodate is
  21. // 2147483647.
  22. //*******************************************************
  23.  
  24. // Read input and pass to BitVector32 instance
  25. uint decNum = uint.Parse(Console.ReadLine());
  26. BitVector32 vector = new BitVector32((int)decNum);
  27.  
  28. // Use regular expression to extract binary number from BitVector32 string representation
  29. string binNum = Regex.Replace(vector.ToString(), @"BitVector32\{0*(?<bin>[01]+)\}", @"${bin}");
  30.  
  31. // Output decimal and binary values to Console
  32. Console.WriteLine("Decimal: {0}", decNum.ToString());
  33. Console.WriteLine("Binary: {0}", binNum);
  34. }
  35. }
  36. }
Success #stdin #stdout 0.04s 38240KB
stdin
1024
stdout
Decimal: 1024
Binary: 10000000000