473,803 Members | 3,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert byte[] into Array?


I need some help converting byte[] into Array:

int bufferLen = Convert.ToInt32 (file.Length);
byte buffer = new byte[bufferLen];
int len = sr.Read(buffer, 0, bufferLen);
ArrayList a = new ArrayList(len);
a.Add(buffer);

Array result = a.toArray();

Something like that...
Nov 17 '05 #1
6 17380
Peter,

An Array class is not the same thing as an ArrayList. When you add an
item to ArrayList, you can only access it by accessing its index. So I
believe you are looking for something like this:

byte[] byteArray = new byte[1];
byteArray[0] = 1;

ArrayList arrayList = new ArrayList(byteA rray.Length);
arrayList.Add(b yteArray);

byte[] someByteArray = (byte[]) arrayList[0];

Best Regards
Johann Blake

Nov 17 '05 #2
> So I
believe you are looking for something like this:


No. :(

I need Array class, because I'm using it in COM automation (SafeArray).

Something like this:

int bufferLen = Convert.ToInt32 (file.Length);
char[] buffer = new char[bufferLen];
int len = sr.Read(buffer, 0, bufferLen);
byte[] tmp = new byte[0]; //Need VT_UI1 automation type. Is this OK?
Array a = Array.CreateIns tance(tmp.GetTy pe(), len);
a.SetValue(buff er);
Nov 17 '05 #3
Does this work for you?
byte[] ba = new byte[2];
Array ar = (Array)ba;

--
William Stacey [MVP]

"Petar Popara" <my*****@mail.n et> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
So I
believe you are looking for something like this:


No. :(

I need Array class, because I'm using it in COM automation (SafeArray).

Something like this:

int bufferLen = Convert.ToInt32 (file.Length);
char[] buffer = new char[bufferLen];
int len = sr.Read(buffer, 0, bufferLen);
byte[] tmp = new byte[0]; //Need VT_UI1 automation type. Is this OK?
Array a = Array.CreateIns tance(tmp.GetTy pe(), len);
a.SetValue(buff er);

Nov 17 '05 #4
Does this work for you?


Yes. :)

I'm beginner with C# and even trivial things confuses me.

Is "byte" same as "unsigned char" (BYTE) in C/C++? I need VT_UI1 automation
(compatible) type.
Nov 17 '05 #5
> Is "byte" same as "unsigned char" (BYTE) in C/C++? I need VT_UI1
automation
(compatible) type.


yes.
Nov 17 '05 #6
Hi,
What you want to do ?

your code should work changing these lines like
byte buffer = new byte[bufferLen];

a.Add(buffer);
for
byte[] buffer = new byte[bufferLen];
a.AddRange( buffer )
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Petar Popara" <my*****@mail.n et> wrote in message
news:uo******** ******@TK2MSFTN GP12.phx.gbl...

I need some help converting byte[] into Array:

int bufferLen = Convert.ToInt32 (file.Length);
byte buffer = new byte[bufferLen];
int len = sr.Read(buffer, 0, bufferLen);
ArrayList a = new ArrayList(len);
a.Add(buffer);

Array result = a.toArray();

Something like that...

Nov 17 '05 #7

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

Similar topics

19
4153
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
1
4490
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding(); now i am using enc.GetString(value) and the value retured is one byte less if the size of the byte array is Odd. In case of files having even number of bytes, the convertion is happening correctly and...
6
10236
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.
15
34614
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
6
53729
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"
12
13569
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} System.Text.UTF8Encoding str = new System.Text.UTF8Encoding(); string s = new string((char)107, 1); s += new string((char)62, 1);
19
5350
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that str(object) does not always attempt to return a string that is acceptable to eval(); its goal is to return a printable string. If no argument is given, returns the empty string, ''.
5
4854
by: da1978 | last post by:
Hi experts, I need to convert a string or a Byte array to a string byte array. Its relatively easy to convert a string to an char array or a byte array but not a STRING byte array. i.e. Dim Array() As Char Dim strwork As String = "76A3kj9d6" Array = strwork.ToCharArray OR
0
10789
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
9699
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...
0
10542
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
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
10068
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...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5496
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...
1
4274
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
3795
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.