As Sergey told you, the code you show won't even compile, at least in C#.
The best, most efficient method is to use the
Buffer
class.
int count = 10;
double[] reals = new double[count];
Random r = new Random();
for (int i = 0; i < count; i++) {
reals[i] = r.NextDouble() * 2000000000.0;
}
count <<= 3;
byte[] result = new byte[count];
Buffer.BlockCopy(reals, 0, result, 0, count);
This will copy the core bits of the double array to the byte array, in
little endian order.
If you need it in big endian order, you need to:
- whether make a
result.Reverse()
after
Buffer.BlockCopy()
.
- or implement your own copy function.
Buffer.BlockCopy Method[
^]
Please, before posting a question, be honest and show some actually compiling code.