开发者

byte array to double conversion in c#

开发者 https://www.devze.com 2023-01-10 06:10 出处:网络
I have an array of three bytes, I want to con开发者_如何学Pythonvert array into double using c#. Kindly guide me.Well, that depends on what you want the conversion to do.

I have an array of three bytes, I want to con开发者_如何学Pythonvert array into double using c#. Kindly guide me.


Well, that depends on what you want the conversion to do.

You can convert 8 bytes (in the right format) into a double using BitConverter.ToDouble - but with only three bytes it's a bit odd - after all, a double has 64 bits of information, normally. How do those three bytes represent a number? What's the format, basically? When you've figured that out, the rest may well be easy.


Well a double is an array of 8 bytes, so with 3 bytes you won't have all the possible values.

To do what you want:

var myBytes[] = {0,0,0,0,0,1,1,2}; //assume you pad your array with enough zeros to make it 8 bytes.
var myDouble = BitConverter.ToDouble(myBytes,0);


Depends on what exactly is stored in the bytes, but you might be able to just pad the array with 5 bytes all containing 0 and then use BitConverter.ToDouble.

0

精彩评论

暂无评论...
验证码 换一张
取 消