Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read the first 3 bytes in byte array

Tags:

c#

I have byte array and I need to read only the first 3 bytes not more.

C# 4.0

like image 584
Mark Avatar asked Sep 24 '10 07:09

Mark


People also ask

How many bytes is a byte array?

Yes, by definition the size of a variable of type byte is one byte. So the length of your array is indeed array.

How do you find byte array?

We can also get the byte array using the below code. byte[] byteArr = str. getBytes("UTF-8");

What is byte array format?

A byte is 8 bits (binary data). A byte array is an array of bytes (tautology FTW!). You could use a byte array to store a collection of binary data, for example, the contents of a file. The downside to this is that the entire file contents must be loaded into memory.

What is byte array size?

The bytearray() method returns a bytearray object, which is an array of the given bytes. The bytearray class is a mutable sequence of integers in the range of 0 to 256.


1 Answers

Any of these enough?

IEnumerable<byte> firstThree = myArray.Take(3);
byte[] firstThreeAsArray = myArray.Take(3).ToArray();
List<byte> firstThreeAsList = myArray.Take(3).ToList();
byte[] firstThreeAsArraySlice = myArray[..3];
like image 142
Jeff Mercado Avatar answered Sep 24 '22 02:09

Jeff Mercado