This could be a very simple CS question but I just still do not get what byte array is in the context of .net framework. I am familiar with standard definitions like array and byte and very familiar with EE concepts such as Byte. But I fail to connect it in terms of CS concepts. I see it used every where and I use it with out really understanding it deeply.
In .Net a byte
is basically a number from 0
to 255
. (the numbers that can be represented by 8 bits)
So, a byte
array is just an array of the numbers 0 - 255.
At a lower level. An array is a contiguous block of memory, and a byte array is just a representation of that memory in 8-bit chunks.
Its an array of byte
. Its binary data - unstructured (in terms of the language at that point in time - different than meaningless!) data which can be arbitrarily long.
Think of loading a picture from a file. You would read the file into a byte[]
before working with the image.
A byte[]
array is simply an array of raw data. For example, a file of size 2000 bytes can be loaded into a byte[]
array of 2000 elements.
A byte is 8 bits, a array of byte, is an array of bytes.. It really is that simple.
The thing to keep in mind is that char and byte are different. In old C style, a char and byte were basically the same thing. in .net, characters are unicode and can be anywhere from 8-32 bits per character. This is where encoding comes into play. You can convert a string to a byte array, and you can convert a byte array into a string by using the Encoding class.
Technically, all of memory is one giant array of bytes (up to 232 addressable bytes in a 32-bit address space). In C# (and C, C++, Java, and many other languages), a byte array is simply a contiguous chunk of memory. Thus a byte[n]
array is a block of n
bytes.
Byte arrays typically have no type other than "byte", which is simply an 8-bit data item.
Byte arrays are generally used for low-level I/O, such as read/write buffers for files and networks, as graphics image buffers, and as "untyped" data streams.
Byte Array: An array which only has elements of Byte type. Byte: Positive integer number between 0 and 255, closed intervallum. A and B are two bytes.
If C = A + B, then, mathematically, C = (A + B) modulo 256 If C = A - B, then, mathematically, C = (A - B) modulo 256
So, you could consider (and sometimes use) your Byte Array of n elements as a number in the radix of 256, with n digits.