C#程序将浮点数转换为二进制
假设以下是我们的浮点数-
float n = 50.5f;
拿一个空字符串显示二进制值并循环,直到我们的float变量的值大于1-
string a = "";
while (n >= 1) {
a = (n % 2) + a;
n = n / 2;
}让我们看完整的例子-
示例
using System;
using System.IO;
using System.CodeDom.Compiler;
namespace Program {
class Demo {
static void Main(string[] args) {
//浮动到二进制
Console.WriteLine("float to binary = ");
float n = 50.5f;
string a = "";
while (n >= 1) {
a = (n % 2) + a;
n = n / 2;
}
Console.Write(a);
}
}
}输出结果
float to binary = 1.5781251.156250.31250.6251.250.5
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短