A little diddy about binary file formats
4 stars based on
Are Computers mystery machines? We have all seen computers do seemingly miraculous things with all kinds of sounds, pictures, graphics, numbers, and text. It seems we can build a replica of parts of our world inside the computer. You might think that this amazing machine is also amazingly complicated - it really is not.
The trick is to take all of the real-world sound, picture, number etc. Computers Are Electronic Machines. The computer uses electricity, not mechanical parts, for its data processing and storage. Electricity is plentiful, moves very fast through wires, and electrical parts fail much less frequently than mechanical parts. The computer does have some mechanical parts, like its disk drive, which are often the sources for computer failuresbut the internal data processing and storage is electronic, which is fast and reliable as long as the computer is plugged in.
Electricity can flow through switches: To process real-world data in the computer, we need a way to represent the data in switches. Computers do this representation using a binary coding system. Binary is a mathematical number system: We have all learned to count using ten digits: One probable reason is that we have ten fingers to represent numbers. The computer has switches to represent data and switches have only two states: Binary has two digits to do the counting: As you can read about in the part of this course on the history of computers, the evolution of how switches were built made computers faster, cheaper, and smaller.
Originally, a switch was a vacuum tube, about the size of a human thumb. In the 's the transistor was invented and won its inventors a Nobel Prize. One binary digit 0 or 1 is referred to, as a bitwhich is design how should i represent to-be binary data for binary digit. Thus, one bit can be implemented by one switch, as shown in Figure 6. In the following table, we see that bits can be grouped together into larger chunks to represent data.
A 0 or 1 is one bit, is four bits, and is eight bits. For several reasons that we do not go into here, computer designers use eight bit chunks called bytes as the basic unit of data. A byte is implemented with eight switches as shown in Figure 6. Computer manufacturers express the capacity of memory and storage in terms of the number of bytes it can hold. The number of bytes can be expressed as kilobytes. Kilo represents 2 to the tenth power, or Kilobyte is abbreviated KB, or simply K.
Thus, the size of a K files is x, orbytes. Some larger files may also be expressed in terms of megabytes x bytes. One megabyte, abbreviated MB, means roughly one million bytes. With storage devices, manufacturers sometimes express memory amounts in terms of gigabytes abbreviated GB ; a gigabyte is roughly a billion bytes.
Modern computer hard disks hold gigabytes e. Here is an important thing to keep in mind: A single byte can represent many different kinds of data. What data it actually represents depends on how the computer uses the byte. For instance, the byte: Since computers cannot think complexly yet! We start with zero and every new thing we count, we go to the next decimal digit - 0,1,2,3,4,5,6,7,8,9. When we reach the end of the decimal digits, we use two digits to count by putting a digit in the "tens place" and then starting over again using our 10 digits.
Eleven is a 1 in the "tens place" and a 1 design how should i represent to-be binary data the "ones place". If we need three digits, likewe use a third digit in the "hundred's place". We do a similar thing to count in binary - except now we only have two digits: What "places" we use depends on the counting system. In the decimal system humans use, which we call Base 10, we use powers of Ten to the second power 10 squared isso we continue in design how should i represent to-be binary data "hundred's place.
Thus, the "places" are two to the zero power "one's place"two to the one power "two's place"two to the second power "four's place"two to the third power "eight's place"and so on. When you look at a byte, the rightmost bit is the "one's place". The next bit is the "two's place", then the "four's design how should i represent to-be binary data, then the "eight's place", and so on.
The largest integer that can be represented in one byte is: For some exercises and more detail on binary numbers, try the exercises at http: Like binary is a number system of Base 2hexadecimal also Base 16or hex is a numeral system of base Hexadecimal uses sixteen distinct symbols: For example, the hexadecimal number "2AF3" is equal, in Binary, toor in Decimal Each hexadecimal digit represents four binary digits, and thus is used in computing to abstract four bits to a single unit - the hex digit.
For example, byte values can range from 0 to decimalbut may be more conveniently represented as two hexadecimal digits in the range 00 to FF. Hex editors, which are used to examine and change binary bits in computing devices, typically use this abstraction to make examination of binary data more reasonable for people.
The computer also uses a single byte to represent a single character. But just what particular set of bits is equivalent to which character? In theory we could each make up our own definitions, declaring certain bit patterns to represent certain characters. Needless to design how should i represent to-be binary data, this would be about as practical as each person speaking his or her own special language.
Since we need to communicate with the computer and with each other, it is appropriate that we use a common scheme for data representation. That is, there must be agreement on which groups of bits represent which characters. Since there are exactly unique combinations of 7 bits, this 7-bit code can represent only characters. Find the character "Escape" below. Thus, when you type a 'C' on the keyboard, circuitry on the keyboard and in the computer converts the 'C' to the byte: If the person typed the word "CAB", it would be design how should i represent to-be binary data by the following three bytes in the computer's memory think of it as three rows of eight switches in memory being ON or OFF:.
In simple graphics those without many colorsa byte can represent a single pixel. In a graphic representation called gray scale each pixel is a shade of grey from black at one extreme to white at the other.
Since eight bytes can hold different integers as described a few paragraphs agoa pixel in one byte can be one of shades of grey usually with 0 being white and being black. See color wheel in Figure We saw that computer manufacturers got together and agreed how characters will be represented the ASCII code. For graphics, there are several similar standards or formats.
One of the original formats still in use is called a bitmap. Design how should i represent to-be binary data store every pixel of the image and thus results in files with large amounts of bytes.
A simple bitmap drawing can easily exceed several megabytes. These files gobble up lots of storage space! File compression, discussed below, doesn't store design how should i represent to-be binary data pixel, but instead stores patterns of pixles. For instance if 20, pixels in a region of the image were all black, instead of storing 20, black pixels, a compression algorithm might store just a few bytes that mean "repeat black 20, times".
This makes JPEG and GIF much better suited to storing on the small flash cards of digital cameras or for downloading over the relatively slow Internet. The size of each image becomes especially important when designing a Web page, sending digital photographs through email, downloading pictures over the Internet, and storing photographs on small flash cards of digital cameras or any other secondary storage device. The primary goal of using these compressed formats such as JPEG and GIF is to shrink the file size to as few bytes as possible without negatively altering the image quality.
Image Quality Affects Size! When considering Web page graphics, the compression ratio is commonly adjusted to make the file size of a graphic smaller. The following images will provide you with an example of the effect that different compression ratios can have on the quality of an image. Each of the images are equal in pixels, x The original image is in the bitmap format; as previously discussed, this format stores every pixel of the image and results in the largest file size.
Digital images can be created by generating pixel patterns using software such as a drawing program like Paint or an original program you write that draws shapes; by manipulating existing digital images; or by combining images. Using existing software such as video editors, or by modified software can create digital effects and animations that you program yourself to include functionality to implement the effects and animations.
Once again the image is greatly reduced in file size. Programs such as Paint Shop Pro and Adobe Photoshop allow you to significantly shrink the size of a file. Most current electronic speakers, the means that we use to electronically reproduce sound, also produce analog waves. However, as we have design how should i represent to-be binary data, all data in the computer is digital and must be processed in bytes.
The process of taking analog data, such as sound, and making it digital is called analog to digital conversion. Many music CD's from old original analog recordings on tapes were converted to digital to be placed on a CD a CD is digital; it is just a collection of bits with a small hole burned in the CD representing a 1 and no hole representing a 0. Current music CD's have the analog to digital conversion done in the recording equipment itself, which produces better conversion.
To convert an design how should i represent to-be binary data wave into digital, converters use a process called sampling.