德尔福转换为Real48 C#双 [英] Convert Delphi Real48 to C# double
本文介绍了德尔福转换为Real48 C#双的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够从一个Delphi Real48转换为C#的两倍。
I need to be able to convert from a Delphi Real48 to C# double.
我有我需要转换,但我找一个优雅的解决方案将字节。的问题。
I've got the bytes I need to convert but am looking for an elegant solution. to the problem.
人在那里收到这样做呢?
Anybody out there had to do this before?
我需要做的转换在C#
在此先感谢
推荐答案
我已经做了一些狩猎周围,我发现了一些C ++代码来完成这项工作,转换它,它似乎给予正确的答案...如果我明白这一切,虽然可恶:•
I've done some hunting around and I found some C++ code to do the job, converted it and it seems to be giving the right answer... damned if I understand it all though :S
private static double Real48ToDouble(byte[] real48)
{
if (real48[0] == 0)
return 0.0; // Null exponent = 0
double exponent = real48[0] - 129.0;
double mantissa = 0.0;
for (int i = 1; i < 5; i++) // loop through bytes 1-4
{
mantissa += real48[i];
mantissa *= 0.00390625; // mantissa /= 256
}
mantissa += (real48[5] & 0x7F);
mantissa *= 0.0078125; // mantissa /= 128
mantissa += 1.0;
if ((real48[5] & 0x80) == 0x80) // Sign bit check
mantissa = -mantissa;
return mantissa * Math.Pow(2.0, exponent);
}
如果有人能解释它,将是巨大的:D
If somebody can explain it that would be great :D
这篇关于德尔福转换为Real48 C#双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文