Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 浮点数的二进制字符串表示返回0_C#_.net - Fatal编程技术网

C# 浮点数的二进制字符串表示返回0

C# 浮点数的二进制字符串表示返回0,c#,.net,C#,.net,当我启动这个控制台应用程序时,我得到的是0,而不是32位字符串。然而,它不会抛出错误 static void Main() { double num = 2.75; byte [] bytes = BitConverter.GetBytes(num); int toInt = BitConverter.ToInt32(bytes, 0); string bitString = Convert.ToString(to

当我启动这个控制台应用程序时,我得到的是
0
,而不是32位字符串。然而,它不会抛出错误

    static void Main()
    {
        double num = 2.75;

        byte [] bytes = BitConverter.GetBytes(num);
        int toInt = BitConverter.ToInt32(bytes, 0);
        string bitString = Convert.ToString(toInt);

        Console.WriteLine(bitString);
    }

double
是64位

您看到的是前32位,它们都是零


你想要
float
(或者调用
ToInt64
查看所有位)。

尝试
Convert.ToString((int)num,2)
@M.kazemAkhgary:那不是他想要的。@M.kazemAkhgary你打印出来的
10
不能隐式地将类型“long”转换为“int”。存在显式转换(是否缺少转换?
此外,我不得不使用
long
,抱怨
float
int-toInt
更改为
long-toInt
@SvetanDimoff@M.kazemAkhgary为什么当我尝试对
num
使用
float
时,我得到类型double的
Literal不能隐式转换为类型“float”;使用“F”后缀创建此类型的文字
?根据定义,
2.75
a
double
,所以我不能使用
float
2.75
是double。写入
2.75f
或像
(float)2.75一样强制转换