我正在创建一个缓冲区,在其中我可以完全消除TCP-Segmentation带来的问题,该缓冲区将读取/写入横幅。唯一遇到的问题是浮点变量,除了浮点数之外,其他都正常工作。我找不到有关如何将int32位转换为浮点数的任何信息。
当将浮点数转换为int位时,使用以下方法(直接从Java源代码中提取并转换)。
当将浮点数转换为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;
}
然而,现在我需要做相反的操作,不幸的是,在BitConverter类中没有任何适用于float类型的函数。
我在JavaDocs中也找不到太多信息,也没有任何我可以个人利用的信息,您可以在这里找到相关信息。
unsafe
不被允许时,这对我来说非常困难。 - Marc Gravell