473,386 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Howto convert a byte array to double array.

Hi everyone,

In c#, what is the fastest way(include unsafe) to

convert a array of bytes(which really contains the

bytes of a double array) to a arry of double.

thanks

kn
Nov 16 '05 #1
5 18770
kevinniu <ke******@hotmail.com> wrote:
In c#, what is the fastest way(include unsafe) to
convert a array of bytes(which really contains the
bytes of a double array) to a arry of double.


Try Buffer.BlockCopy - that should be pretty fast.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
if you want to prvent the copying use mixed mode C++, using unmanaged C++ you can get a void* pointer to the managed buffer, then you can do with it whatever you want...

Mixed mode C++ array manipulation ( access a System::Byte array as an 'unsigned short' array):
virtual int ManipArray(System::Byte btArray __gc[])
{
int i = 0;
BYTE __pin *pbtArray = &btArray[0];
unsigned short *uiArray = (unsigned short*)pbtArray;
for(i; i < btArray->Length/2; i++)
uiArray[i] <<= 1;
return 0;
}

--
Nadav
http://www.ddevel.com
"kevinniu" wrote:
Hi everyone,

In c#, what is the fastest way(include unsafe) to

convert a array of bytes(which really contains the

bytes of a double array) to a arry of double.

thanks

kn

Nov 16 '05 #3
Nadav,

Thanks for the reply.

Is it possible to use unsafe code in C# to get the same result?

You know I am programming in C# and I am not familiar with mixed C++.

Any idea?

Regards

kevin

"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
if you want to prvent the copying use mixed mode C++, using unmanaged C++ you can get a void* pointer to the managed buffer, then you can do with it
whatever you want...
Mixed mode C++ array manipulation ( access a System::Byte array as an 'unsigned short' array): virtual int ManipArray(System::Byte btArray __gc[])
{
int i = 0;
BYTE __pin *pbtArray = &btArray[0];
unsigned short *uiArray = (unsigned short*)pbtArray;
for(i; i < btArray->Length/2; i++)
uiArray[i] <<= 1;
return 0;
}

--
Nadav
http://www.ddevel.com
"kevinniu" wrote:
Hi everyone,

In c#, what is the fastest way(include unsafe) to

convert a array of bytes(which really contains the

bytes of a double array) to a arry of double.

thanks

kn

Nov 16 '05 #4
Jon,

Thanks for your reply.

I have tried with the BlockCopy, as I have a lot of data,

I really need to speed thing up..

Any other ways to improve the performance?

Best Regards

Kevin

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
kevinniu <ke******@hotmail.com> wrote:
In c#, what is the fastest way(include unsafe) to
convert a array of bytes(which really contains the
bytes of a double array) to a arry of double.


Try Buffer.BlockCopy - that should be pretty fast.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
Lin Liang <l.******@pgrad.unimelb.edu.au> wrote:
Is it possible to use unsafe code in C# to get the same result?

You know I am programming in C# and I am not familiar with mixed C++.

Any idea?


I should think you could just use unsafe code and write almost exactly
the same code in C#. See a tutorial on unsafe code for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
15
by: jeko | last post by:
Hi, is it possible to read a double variable one byte at a time. I would want store each byte into unsigned char and then assemble again the double variable again. thanx Andrea
3
by: Michael | last post by:
Hallo NG, a few jears ago i made myself in c++ a funktion to convert 4 Byte to one float variable: //########################################################### // Make from 4 Bytes one float...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
3
by: MuZZy | last post by:
Hi, I just wonder if someone can help me wit this - i have a byte array and need to convert it to short array, creating short numbers by combining bytes by pairs: My array: byte, byte, byte,...
2
by: antonio matos | last post by:
hi people. I have to acess a database, and there are some fields that are binary. when i acess that field is read like an array of bytes. but in reality it's an array of doubles!!! how can...
6
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
1
by: Paul Jarvis | last post by:
I have a large structure, below is a simplistic version of my structure: public struct MeanMinMaxSd { public double mean; public double min; public double max; public double sd; }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.