Reputation: 18684
I have a byte[8], which is actually a sequential number. It comes from the RowVersion in a database.
I am really just concerned about the last 4 bytes of the 8 byte array.
I am trying to do this:
Version = BitConverter.ToDouble(t.Version,4)
'Version' is a double. But, I get an error saying that:
Destination array is not long enough to copy all the items in the collection. Check array index and length.
The value of my 'Version' is:
[0]0 [1]0 [2]0 [3]0 [4]0 [5]0 [6]12 [7]102
What am I doing wrong?
Upvotes: 5
Views: 6758
Reputation: 125610
double
requires 8 bytes, so you should get only one from your entire byte[]
:
BitConverter.ToDouble(input, 0);
returns
3.7179659497173697E+183
Update
But because you're saying it's a rowversion
value, you should convert it to long
instead of double
:
BitConverter.ToInt64(input, 0);
returns
7353252291589177344
Upvotes: 6
Reputation:
Use this code:
double[] array= bytearray.Select(i => (double)i).ToArray();
Update:
BitConverter.ToDouble(yournumber, 0);
Upvotes: 0