Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
microsoft.public.dotnet.framework.sdk
Type Conversion
John Ma
5/3/2002 3:57:00 AM
How can I convert a int array to a byte array.
In an other word, I need to write a int array into a
memorystream. How can I do it?
Thanks
4 Answers
Mattias Sjögren
5/3/2002 1:45:00 PM
0
John,
>How can I convert a int array to a byte array.
>In an other word, I need to write a int array into a
>memorystream. How can I do it?
The easiest way is to create a BinaryWriter on top of the
MemoryStream, then iterate through the int[] and call Write for each
element.
You can also use the BitConverter class to get byte[4] from an int.
Mattias
==Mattias Sjögren (VB MVP)
mattias @ mvps.org
http://www.msjogren.n...
NETMaster
5/3/2002 2:45:00 PM
0
what about Buffer.BlockCopy() ?
--
NETMaster (Thomas Scheidegger)
http://www.cetus-links.org/oo_c...
"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message news:#39U#fp8BHA.220@tkmsftngp04...
> >How can I convert a int array to a byte array.
> >In an other word, I need to write a int array into a
> >memorystream. How can I do it?
> The easiest way is to create a BinaryWriter on top of the
> MemoryStream, then iterate through the int[] and call Write for each
> element.
> You can also use the BitConverter class to get byte[4] from an int.
NETMaster
5/3/2002 2:50:00 PM
0
int[] ai = new int[] { 0x11223344, 0x55667788 };
byte[] ab = new byte[ Buffer.ByteLength(ai) ];
Buffer.BlockCopy( ai, 0, ab, 0, ab.Length );
--
NETMaster (Thomas Scheidegger)
http://www.cetus-links.org/oo_c...
"NETMaster" <spam.netmaster@swissonline.ch> wrote in message news:u307oBq8BHA.2256@tkmsftngp05...
> what about Buffer.BlockCopy() ?
Mattias Sjögren
5/3/2002 3:21:00 PM
0
>what about Buffer.BlockCopy() ?
Even better! :-)
Mattias
==Mattias Sjögren (VB MVP)
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Type Conversion
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password