What is a Byte?
When you store data in a computer, you often refer to the number of bytes of memory you have in the computer. You may talk of megabytes in RAM (Random Access Memory) or gigabytes available on your hard drive. A byte is a basic measure of memory, and you need to know about bytes if you want to really understand memory.
Memory is really composed of bits. However, bits are often organized
into larger units of eight bits, and that's a byte. Shown below is
a byte with eight bits of data.
|
|
|
|
|
|
|
|
|
This byte of data can be interpreted in at least two different ways.
Our decimal number system lets us use numbers like 683 when we mean:
683 = 6*102 + 8*101 + 3*100
In other words, our decimal number system is a positional number system using a base of ten (10). The data in the byte can be interpreted as a binary number using a base of two (2). Then, the number in the byte above can be thought of as:
1*27 + 0*26 + 1*25 + 0*24 + 0*23 + 1*22 + 1*21 + 1*20
Then, if you add that up, taking into account the values of the powers of 2 in the decimal system, we get:
128 + 32 + 4 + 2 + 1 = 167 (in decimal terms)
It should
be obvious that you can have any number from 0 to 255 represented in this
scheme.
Question:
Why is the upper limit 255?
The ASCII code is one other way to code the information in a byte. In the ASCII code, the 255 possible patterns are used to represent all the letters in the alphabet (both lower case and upper case), punctuation marks (periods, commas, apostrophes, spaces, tab characters, etc.). When you type (as the author of these lessons is doing to write this) the letters and everything else you type is translated so that every keystroke is stored in a byte that can be interpreted as one of those characters. If you click on the link above, you can see how the ASCII code is implemented. You get a table that shows how the character set representation corresponds to the usual numerical representation (the 0-255 representation).
The important point here is that a byte (8 bits) can have 256 different combinations of ones and zeroes inserted into the eight slots. Using the first representation above, you can represent the numbers from 0 to 255 in a single byte, and that representation makes sense because it can be interpreted as a number in a binary number system. Using the ASCII code representation the 256 combinations are used to represent characters. It's up to you what the bit patterns mean. If you are typing a paper, then you want the computer to interpret the bit patterns as characters. If you are measuring data with an A/D converter, then the bit patterns should be interpreted as representing numbers that are tied back to numerical values of voltage. (There is usually a linear relationship between the integer representation of the number and the voltage being converted. See the lesson on A/D converters in the link above.) A pattern of zeroes and ones in a byte means different things using different interpretation, and you can have some interesting situations when you bring up a file that interprets data differently than you expect. (Try opening an executable file - where the bytes are data and instructions mixed together - in a text editor, just for a few laughs.)
However, there are even other binary number representations that make sense. For example, one of the bits (say the first bit) in the byte can be interpreted as a sign bit, and the other seven bits can be thought of as representing the numbers from 0 to +127. (This scheme has the disadvantage that there are two zeroes, +0 and -0.) It is also possible to map the numbers from -128 to +127 into the 255 possibilities. In any event, what the bit patterns in a byte represent is completely arbitrary and can be anything you choose.