Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.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
Vb.net 将整数强制转换为单个保留位表示形式_Vb.net_Casting - Fatal编程技术网

Vb.net 将整数强制转换为单个保留位表示形式

Vb.net 将整数强制转换为单个保留位表示形式,vb.net,casting,Vb.net,Casting,在VB.NET中,有没有一种快速的方法可以在保留底层位结构的同时将32位int转换为32位浮点?BitConverter可以做到这一点,但我想直接强制转换它,而不涉及字节数组。该死,我怎么可能忘记C样式的联合呢 <Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Explicit)> _ Public Structure IntFloatUnion <Runtime.Inter

在VB.NET中,有没有一种快速的方法可以在保留底层位结构的同时将32位int转换为32位浮点?BitConverter可以做到这一点,但我想直接强制转换它,而不涉及字节数组。

该死,我怎么可能忘记C样式的联合呢

<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Explicit)> _
Public Structure IntFloatUnion
    <Runtime.InteropServices.FieldOffset(0)> Public i As Integer
    <Runtime.InteropServices.FieldOffset(0)> Public f As Single
End Structure


Sub Main()
    Dim u As IntFloatUnion

    u.i = 42
    Console.WriteLine(u.f)

    Console.ReadLine()
End Sub
这可以编译成一个单独的dll,并从VB项目中引用。

你所说的“保留底层位结构”是什么意思?你为什么需要它?我正在使用它来改善瓶颈中的性能,我正在为一些函数寻找绝对最快的位攻击。