What do we mean byte array?

Can someone explain, I definitely don’t understand him

What is a byte array
Where and when do we use it in applications / programs
what are the advantages and disadvantages of using a byte array

+60
java computer-science bytearray
Oct 26 '10 at 0:22
source share
3 answers

Byte - 8 bits (binary data).

A byte array is an array of bytes (FTW tautology!).

You can use an array of bytes to store a collection of binary data, such as the contents of a file. The disadvantage of this is that the entire contents of the file must be loaded into memory.

For large amounts of binary data, it would be better to use a streaming data type if your language supports it.

+43
Oct 26 '10 at 0:29
source share

I assume you know what a byte is. A byte array is just a memory area containing a group of adjacent (side by side) bytes, so it makes sense to talk about them in order: the first byte, the second byte, etc.

Just as bytes can encode different types and ranges of data (digits from 0 to 255, numbers from -128 to 127, single characters using ASCII, for example, β€œa” or β€œ%”, CPU codes), each byte in an array of bytes can be any of these things or contribute to some multibyte values, such as numbers with a wide range (for example, a 16-bit unsigned int from 0..65535), international character sets, text strings ("hello") or part / all compiled computer programs.

The important thing about a byte array is that it gives indexed (fast), accurate, raw access to every 8-bit value stored in this piece of memory, and you can control these bytes to control each individual bit. The bad news is that the computer simply treats each record as an independent 8-bit number, which may be related to your program, or you may prefer some powerful data type, such as a string that tracks its own length and grows as needed. or a floating point number that allows you to store the value of 3.14 without thinking about the broken representation. As a data type, it is inefficient to insert or delete data near the beginning of a long array, since all subsequent elements must be shuffled to create or fill the created / necessary gap.

+23
Oct 26 '10 at 1:14
source share

From wikipedia :

In computer science, an array data structure or simply an array is a data structure consisting of a collection of elements (values ​​or variables), each of which is identified by one or more integer numbers of indices stored so that the address of each element can be calculated from the index tuple by a simple mathematical formula .

So, when you say an array of bytes, you mean an array of a certain length (for example, the number of elements) that contains a set of elements of byte size (8 bits).

In C #, an array of bytes might look like this:

byte[] bytes = { 3, 10, 8, 25 }; 

The above example defines an array of 4 elements, each of which may contain a Byte length.

+5
Oct 26 '10 at 0:32
source share



All Articles