how to convert bytes array?

G

Guest

Hello, I have a question.
byte[] network = new byte[100];
And I know what in this byte array in position from 4 to 8 it is long value,
and from 10 to 12 is it ushort type.

I need do something like this
long val1 = (long)network[4-8];
ushort val2 = (ushort )network[10-12];

So I need get few bytes from some position and convert them to some value
type.
How can i do this?
 
P

Peter Duniho

SushiSean said:
[...]
So I need get few bytes from some position and convert them to some value
type.
How can i do this?

You may find the BitConverter class useful for the purpose.
 
M

Michael C

SushiSean said:
Hello, I have a question.
byte[] network = new byte[100];
And I know what in this byte array in position from 4 to 8 it is long
value,
and from 10 to 12 is it ushort type.

I need do something like this
long val1 = (long)network[4-8];
ushort val2 = (ushort )network[10-12];

Note that the value is in bytes 4 to 7 and 10 to 11.

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top