473,748 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 18830
kevinniu <ke******@hotma il.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.BlockCop y - that should be pretty fast.

--
Jon Skeet - <sk***@pobox.co m>
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(Syst em::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***@discussi ons.microsoft.c om> wrote in message
news:98******** *************** ***********@mic rosoft.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(Syst em::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.co m> wrote in message
news:MP******** *************** @msnews.microso ft.com...
kevinniu <ke******@hotma il.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.BlockCop y - that should be pretty fast.

--
Jon Skeet - <sk***@pobox.co m>
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.co m>
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
13925
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 something like: char chars = "Hello!"; byte bytes = (byte) chars;
15
3594
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
54814
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 variable wich is 4 bytes long //########################################################### float CAtgGalvanoMachine::Convert4BytesToFloat(BYTE byte1, BYTE byte2, BYTE byte3, BYTE byte4)
6
10224
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 the data converted from the byte array into a string , is not what i expect. example: - the data returned from the socket is (byte array) "Usuario Sin Atribuciones Para Esta Función"
3
10364
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, etc. I need: short = byte+byte, short = byte+byte, etc.
2
9374
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 i convert from a byte array to a double array?
6
2783
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) using redim arrays to add to a normal byte array (2) using an ArrayList and finally (3) using a memorystream. These three classes are listed below the test sub called "TestBuildByteArray". It was interesting that using the memorystream was...
6
53723
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 do I convert it to: dim myStr as string = "11,22,33,44"
1
3792
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
8995
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9332
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.