Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to convert floating to binary
Let’s say the following is our float −
float n = 50.5f;
Take an empty string to display the binary value and loop until the value of our float variable is greater than 1 −
string a = "";
while (n >= 1) {
a = (n % 2) + a;
n = n / 2;
}
Let us see the complete example −
Example
using System;
using System.IO;
using System.CodeDom.Compiler;
namespace Program {
class Demo {
static void Main(string[] args) {
// float to binary
Console.WriteLine("float to binary = ");
float n = 50.5f;
string a = "";
while (n >= 1) {
a = (n % 2) + a;
n = n / 2;
}
Console.Write(a);
}
}
}
Output
float to binary = 1.5781251.156250.31250.6251.250.5
Advertisements