相关疑难解决方法(0)

如何通过float表示将float转换为uint?

C我将这样做以将数字的浮点表示转换为DWORD.从地址中获取值并将内容转换为DWORD.

dwordVal = *(DWORD*)&floatVal;
Run Code Online (Sandbox Code Playgroud)

所以例如44.54321将成为0x42322C3F.

我怎么能这样做C#呢?

c# floating-point int

7
推荐指数
1
解决办法
4425
查看次数

c#如何将float转换为int

我需要将float转换为int(单精度,32位),如:
'float:2(hex:40000000)to int:1073741824'.知道如何实现吗?
我在msdn帮助中寻找它但没有结果.

c# floating-point int

3
推荐指数
2
解决办法
5440
查看次数

将int位转换为浮点位

我正在创建一个缓冲区,它将在横幅中读/写,我可以完全消除TCP分段带来的问题.我遇到的唯一问题是浮点变量,其他一切工作正常,除了浮点数.我找不到有关如何将int32位转换为float的任何信息.

将float转换为int位时,使用以下方法(直接从java的源代码中删除并转换)

private int floatToIntBits(float value)
{
    int result = BitConverter.ToInt32(BitConverter.GetBytes(value), 0);
    if (((result & 0x7F800000) == 0x7F800000) && (result & 0x80000000) != 0)
        result = 0x7fc00000;
    return result;
}
Run Code Online (Sandbox Code Playgroud)

但是,现在我需要做相反的事情,遗憾的是,BitConverter类中没有任何与float一起使用的函数.

我也无法在JavaDocs中找到很多信息,而不是我个人可以使用的任何信息,你可以在这里找到信息.

c# bit-manipulation

3
推荐指数
3
解决办法
4019
查看次数

标签 统计

c# ×3

floating-point ×2

int ×2

bit-manipulation ×1