Advertisement
petromaxa

Untitled

Jan 30th, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _9.FloatingPointBinaryRepresentation
  7. {
  8. class FloatingPointBinaryRepresentation
  9. {
  10. static void Main()
  11. {
  12. float number;
  13. bool isCorrectEntry = false;
  14. Console.WriteLine("Enter an number:");
  15. isCorrectEntry = float.TryParse(Console.ReadLine(), out number);
  16. if (isCorrectEntry == false)
  17. {
  18. Console.WriteLine("Wrong entry!");
  19. return;
  20. }
  21. long longNumber = BitConverter.DoubleToInt64Bits(number);
  22. string stringNumber = Convert.ToString(longNumber, 2).PadLeft(64,'0');
  23. string sign = stringNumber.Substring(0, 1);
  24. string exponent = stringNumber.Substring(1, 1) + stringNumber.Substring(5, 7);
  25. string mantisa = stringNumber.Substring(12, 23);
  26. Console.WriteLine("{0,-6}{1,-15}{2,23}", sign, exponent, mantisa);
  27. Console.WriteLine("{0,-6}{1,-15}{2,-23}", "sign", "exponent", "mantisa");
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement