[英]Decompression of 2 byte to 4 byte float
I have some animation data (x,y,z), which is represented as 2 byte structures and written in Little Endian.我有一些动画数据 (x,y,z),它表示为 2 字节结构并用 Little Endian 编写。 I know that they should be a 4 byte floating point, so i have to unpack them.
我知道它们应该是一个 4 字节的浮点数,所以我必须解压它们。 I collected a few sample values as precise as it was possible (they doesn't represent exactly packed values, but very close to them) and roughly divided packed values on few ranges.
我尽可能精确地收集了一些样本值(它们不代表精确的压缩值,但非常接近它们)并在几个范围内粗略地划分压缩值。
There are gaps (....) on the ends of ranges because it is hard to check them correctly, but i assume such big values which are lying close to these ends doesn't used in practice.范围的末端有间隙(....),因为很难正确检查它们,但我认为靠近这些末端的如此大的值在实践中不会使用。
Also, it looks like a symmetry between positive and negative ranges, for example i tested 0x0058 which gave 1.003879905 and 0x00D8 which gave value close to -1.003879905 but not precise.此外,它看起来像正负范围之间的对称性,例如我测试了0x0058 ,它给出了1.003879905和0x00D8 ,它给出的值接近-1.003879905但不精确。 Maybe it happened because of slightly offset observed after 0x0080 , when visible decreasing starts from 0x00B0 , but it should be about 0x0094 if entire range had equal symmetry.
可能是因为在0x0080之后观察到的轻微偏移而发生的,当可见减少从0x00B0开始时,但如果整个范围具有相等的对称性,它应该约为0x0094 。 But slight measure inaccuracy might be as well.
但轻微的测量不准确也可能是。
So, how to get a function in C#, that will convert source data to 4 byte floating point?那么,如何在 C# 中获取一个函数,将源数据转换为 4 字节浮点数?
Some initial comments based on the information in the question so far:到目前为止,基于问题中的信息的一些初步评论:
byte[] buffer = new byte[4];
is a bad approach because it addresses bytes individually while the other code manipulates bits using shifts within words, and C# does not define endianness.num2
is zero and num3
is not zero, the significand ( num3
) must be shifted and the exponent ( num2
) must be adjusted.num2
为零且num3
不为零,则必须移动有效数 ( num3
) 并且必须调整指数 ( num2
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.