Chapter 2 Data Representation 2 1 DATA TYPES

  • Slides: 20
Download presentation
Chapter 2 Data Representation 主讲:李艳 云南农业大学

Chapter 2 Data Representation 主讲:李艳 云南农业大学

2. 1 DATA TYPES Data today come in different forms such as numbers, text,

2. 1 DATA TYPES Data today come in different forms such as numbers, text, images, audio, and video. People need to process all these data types. The computer industry uses the term “multimedia” to define information that contains numbers, text, images, audio, and video. 计算机导论

2. 2 DATA INSIDE THE COMPUTER All data types from outside a computer are

2. 2 DATA INSIDE THE COMPUTER All data types from outside a computer are transformed into a uniform representation when stored in a computer and then transformed back when leaving the computer. This universal format is called a bit pattern. BIT A bit (binary digit) is the smallest unit of data that can be stored in a computer; it is either 0 or 1. BIT PATTERN A bit pattern is a sequence, or as it is sometimes called, a string of bits that can represent a symbol. e. g. BYTE A bit pattern of length 8 is called a byte. 计算机导论

2. 3 REPRESENTING DATA TEXT A piece of text in any language is a

2. 3 REPRESENTING DATA TEXT A piece of text in any language is a sequence of symbols used to represent an idea in that language. You can represent each symbol with a bit pattern. In other words, text such as “BYTE”, which is made of four symbols, can be represented as 4 bit patterns, each pattern defining a single symbol. 计算机导论

How many bits are needed in a bit pattern to represent a symbol in

How many bits are needed in a bit pattern to represent a symbol in a language? The length of the bit pattern that represents a symbol in a language depends on the number of symbols used in that language. More symbols mean a longer bit pattern. The relationship is not linear; it is logarithmic. If you need n symbols, the length is log 2 n bit. Number of Symbols ----------- Bit Pattern Length ----------- 128 256 … 7 8 … 2 4 8 16 … 1 2 3 4 … 计算机导论

Codes Different sets of bit patterns have been designed to represent text symbols. Each

Codes Different sets of bit patterns have been designed to represent text symbols. Each set is called a code, and the process of representing symbols is called coding. ASCII The American National Standards Institute (ANSI) developed a code called American Standard Code for Information Interchange (ASCII). This code uses 7 bits for each symbol. This means 128 different symbols can be defined by this code. e. g. 计算机导论

The following highlights some features of this code: Ø ASCII uses a 7 -bit

The following highlights some features of this code: Ø ASCII uses a 7 -bit pattern ranging from 0000000 to 1111111. Ø The numeric characters (0 to 9) are coded before letters. Ø The uppercase letters (A. . . Z) come before the lowercase letters (a. . . z). Ø The upper-and lowercase characters are distinguished by only 1 bit. For example, the pattern for A is 1000001; the pattern for a is 1100001. The only difference is in the sixth bit from the right. …… 计算机导论

IMAGES Images today are represented in a computer by one of two methods: bitmap

IMAGES Images today are represented in a computer by one of two methods: bitmap graphic or vector graphic. Bitmap Graphic In this method, an image is divided into a matrix of pixels (picture elements), where each pixel is a small dot. The size of the pixel depends on what is called the resolution. After dividing an image into pixels, each pixel is assigned a bit pattern. The size and the value of the pattern depend on the image. 计算机导论

To represent color images, each colored pixel is decomposed into three primary colors: red,

To represent color images, each colored pixel is decomposed into three primary colors: red, green, and blue (RGB). Then the intensity of each color is measured, and a bit pattern (usually 8 bits) is assigned to it. In other words, each pixel has three bit patterns: one to represent the intensity of the red color, one to represent the intensity of the green color, and one to represent the intensity of the blue color. 计算机导论

Vector Graphic The vector graphic method does not store the bit patterns. An image

Vector Graphic The vector graphic method does not store the bit patterns. An image is decomposed into a combination of curves and lines. Each curve or line is represented by a mathematical formula. For example, a line may be described by the coordinates of its endpoints, and a circle may be described by the coordinates of its center and the length of its radius. The combination of these formulas is stored in a computer. When the image is to be displayed or printed, the size of the image is given to the system as an input. The system redesigns the image with the new size and uses the same formula to draw the image. In this case, each time an image is drawn, the formula is reevaluated. 计算机导论

AUDIO Audio is converted to digital data, then we can use bit patterns to

AUDIO Audio is converted to digital data, then we can use bit patterns to store them. Audio is by nature analog data. It is continuous (analog), not discrete (digital). 计算机导论

The steps to change audio data to bit patterns as follows: Ø The analog

The steps to change audio data to bit patterns as follows: Ø The analog signal is sampled. Sampling means measuring the value of the signal at equal intervals. Ø The samples are quantized. Quantization means assigning a value (from a set) to a sample. For example, if the value of a sample is 29. 2 and the set of integers between 0 and 63, the sample is assigned a value of 29. Ø The quantized values are changed to binary patterns. For example, the number 25 is changed to the binary pattern 0001 1001. Ø The binary patterns are stored. 计算机导论

2. 4 HEXADECIMAL NOTATION Hexadecimal notation is based on 16 (hexadec is Greek for

2. 4 HEXADECIMAL NOTATION Hexadecimal notation is based on 16 (hexadec is Greek for 16). This means there are 16 symbols (hexadecimal digits): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. Each hexadecimal digit can represent 4 bits, 4 bits can be represented by a hexadecimal digit. Bit Pattern Hex Digit ----------------------0 8 0000 1 9 0001 1001 2 A 0010 1010 3 B 0011 1011 4 C 0100 1100 5 D 0101 1101 6 E 0110 1110 7 F 0111 1111 计算机导论

CONVERSION Converting from a bit pattern to hexadecimal is done by organizing the pattern

CONVERSION Converting from a bit pattern to hexadecimal is done by organizing the pattern into groups of four and finding the hexadecimal value for each group of 4 bits. For hexadecimal to bit pattern conversion, convert each hexadecimal digit to its 4 -bit equivalent. Hexadecimal notation is written in two formats. In the fist format, you add a lowercase (or uppercase) x before the digits. For example, x. A 34; In another format, you indicate the base of the number (16) as the subscript after the notation. For example, (A 34)16. 计算机导论

Example 1 Show the hexadecimal equivalent of the bit pattern 1100 1110 0010. Solution

Example 1 Show the hexadecimal equivalent of the bit pattern 1100 1110 0010. Solution Each group of 4 bits is translated to one hexadecimal digit. The equivalent is x. CE 2. 计算机导论

Example 2 Show the hexadecimal equivalent of the bit pattern 0011100010. Solution Divide the

Example 2 Show the hexadecimal equivalent of the bit pattern 0011100010. Solution Divide the bit pattern into 4 -bit groups (from the right). In this case, add two extra 0 s at the left to make the number of bits divisible by 4. So you have 000011100010, which is translated to x 0 E 2. 计算机导论

Example 3 What is the bit pattern for x 24 C? Solution Write each

Example 3 What is the bit pattern for x 24 C? Solution Write each hexadecimal digit as its equivalent bit pattern to get 001001001100. 计算机导论

SUMMARY Ø Numbers, text, images, audio, and video are all forms of data. Computers

SUMMARY Ø Numbers, text, images, audio, and video are all forms of data. Computers need to process all types of data. Ø All data types are transformed into a uniform representation called a bit pattern for processing by computers. Ø A bit is the smallest unit of data that can be stored in a computer. Ø A bit pattern is a sequence of bits that can represent a symbol. Ø A byte is 8 bits. 计算机导论

SUMMARY (continued) Ø Coding is the process of transforming data into a bit pattern.

SUMMARY (continued) Ø Coding is the process of transforming data into a bit pattern. Ø ASCII is a popular code for symbols. Ø Images use the bitmap graphic or vector graphic method for data representation. The image is broken up into pixels which can then be assigned bit patterns. Ø Audio data are transformed to bit patterns though sampling, quantization, and coding. Ø Video data are a set of sequential images. 计算机导论