Advertisement
stanevplamen

02.04.08.ShortBinaryPresentation

Jul 22nd, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2.  
  3. class ShortBinaryPresentation
  4. {
  5.     static void Main()
  6.     {
  7.         // Just for test
  8.         short positiveShort = 32767;
  9.         string binaryPresentationOne = Convert.ToString(positiveShort, 2);
  10.         Console.WriteLine("The binary presentation of positive Short integer is {0}", binaryPresentationOne.PadLeft(16, '0'));
  11.  
  12.         short negativeShort = -3260;
  13.         string binaryPresentationTwo = Convert.ToString(negativeShort, 2);
  14.         Console.WriteLine("The binary presentation of negative Short integer is {0}", binaryPresentationTwo.PadLeft(16, '0'));
  15.  
  16.         // The task
  17.         Console.Write("Please enter a Short type integer: ");
  18.         short shortToConvert = short.Parse(Console.ReadLine());
  19.         string binaryPresentation = Convert.ToString(shortToConvert, 2);
  20.         Console.WriteLine("The binary presentation of the given number is {0}", binaryPresentation.PadLeft(16, '0'));
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement