
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- Python program to convert floating to binary
- Java program to convert floating to binary
- C# Program to Convert Binary to Decimal
- C# program to convert binary string to Integer
- C# Program to Convert Decimal to Binary\n
- C++ Program To Convert Decimal Number to Binary
- C++ Program to Convert Hexadecimal Number to Binary
- C++ Program to Convert Octal Number to Binary Number
- C program to convert decimal fraction to binary fraction
- 8085 program to convert gray to binary
- 8085 Program to convert ASCII to binary
- Haskell Program to convert Binary to Octal
- Golang Program to convert Binary to Octal
- Haskell Program to convert Decimal to Binary
- Haskell Program to convert Binary to Decimal

Advertisements