Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace _9.FloatingPointBinaryRepresentation
- {
- class FloatingPointBinaryRepresentation
- {
- static void Main()
- {
- float number;
- bool isCorrectEntry = false;
- Console.WriteLine("Enter an number:");
- isCorrectEntry = float.TryParse(Console.ReadLine(), out number);
- if (isCorrectEntry == false)
- {
- Console.WriteLine("Wrong entry!");
- return;
- }
- long longNumber = BitConverter.DoubleToInt64Bits(number);
- string stringNumber = Convert.ToString(longNumber, 2).PadLeft(64,'0');
- string sign = stringNumber.Substring(0, 1);
- string exponent = stringNumber.Substring(1, 1) + stringNumber.Substring(5, 7);
- string mantisa = stringNumber.Substring(12, 23);
- Console.WriteLine("{0,-6}{1,-15}{2,23}", sign, exponent, mantisa);
- Console.WriteLine("{0,-6}{1,-15}{2,-23}", "sign", "exponent", "mantisa");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement