VladoG

[C# Adv] ManualStrProcessing-Exercise-03. Formatting Numbers

Jun 14th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03_FormattingNumbers
  4.     {
  5.     class FormattingNumbers
  6.         {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] input = Console.ReadLine()
  10.                 .Split(new char[] {' ', '\t'}, StringSplitOptions.RemoveEmptyEntries);
  11.  
  12.             int a = int.Parse(input[0]);
  13.             string aBinary = Convert.ToString(a, 2)
  14.                 .PadLeft(10, '0')
  15.                 .Substring(0, 10); // If more than 10 bits - get first 10 bits !!!
  16.  
  17.             double b = double.Parse(input[1]);
  18.             double c = double.Parse(input[2]);
  19.  
  20.             Console.WriteLine(string.Format("|{0,-10:X}|{1}|{2,10:F2}|{3,-10:F3}|",a , aBinary, b, c));
  21.  
  22.             }
  23.         }
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment