简体   繁体   English

C#-将双精度值转换为[8字节IEEE浮点数],然后再次返回

[英]C# - Convert double value to [8 byte IEEE floating point] AND back again

Hope you can help me with this problem. 希望你能帮助我解决这个问题。

I am working for a client and in his technical notes I need to SEND a double value to a IEEE Floating 8byte point in C#. 我正在为一个客户工作,在他的技术说明中,我需要向C#中的IEEE Floating 8byte point 发送一个 精度值 This is just the one part, after that I need to be able to RECEIVE a IEEE Floating 8byte point and extract the double from it. 这只是一部分,在那之后,我需要能够接收 IEEE Floating 8byte point,并从中提取出double值。

The specific value that I am receiving is 19500.00. 我收到的特定值为19500.00。

I have been searching the net a while, but think my Google skills left me hanging! 我已经在网上搜寻了一段时间,但是认为我的Google技能使我垂涎三尺!

Any help will be appreciated, but code will be preferred. 任何帮助将不胜感激,但代码将是首选。

The answer was very simple: 答案很简单:

double value = 19500.00; 双精度值= 19500.00;

This gives the bytes: 这给出了字节:

var bytes = BitConverter.GetBytes(value); var bytes = BitConverter.GetBytes(value);

This gives the double again: 这再次使双倍:

var value = BitConverter.ToDouble(bytes, 0); var value = BitConverter.ToDouble(bytes,0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM