500 likes | 606 Views
Chapter 2. Data Representation. O BJECTIVES. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images, video, and audio. Work with hexadecimal and octal notations. Define data types. After reading this chapter, the reader should be able to:.
E N D
Chapter 2 Data Representation
OBJECTIVES Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,video, and audio. Work with hexadecimal and octal notations. Define data types. After reading this chapter, the reader should be able to:
Figure 2-1 Different types of data
Uses of Computer in Various Program • Engineering: to process numbers, do arithmetic, solve algebraic, trigonometric, equation • Word processing: process text, justify, move, delete • Image processing: to manipulate images, create, shrink, expand, rotate • Audio: play music, record voice • Video: Play movie, create special effects
Note: The computer industry uses the term“multimedia” to define information that contains numbers, text, images, audio, and video.
2.2 DATA INSIDE THE COMPUTER
Question? • How do you handle all these data types? • Do you have different computers process different types of data? • Do you have a category of computers that processes only numbers? • Do you have a category of computers that processes only text?
Solution • Solution of different computers to process different types of data is neither economical nor practical because data is usually a mixture of types. • Most efficient solution: to use a uniform representation. All data from outside a computer are transformed into this uniform representation when stored in a computer and then transformed back when leaving the computer. • It is called a bit pattern
Figure 2-2 Bit pattern • To represent different types of data • Or called a sequence, a string of bits • Figure above shows a bit pattern made of 16 bits • If you need to store a bit pattern made of 16 bits, you need 16 electronic switches. • If need to store 1000 bit patterns, each 16 bits, you need 16 000 switches.
How does computer memory know what type of data a stored bit pattern represent? • It does not. • Computer memory just stores the data as bit patterns. • It is the responsibility of input/output devices or programs to interpret a bit pattern as a number, text or some other type of data. • Data are coded when they enter a computer and decoded when they are presented to the user.
Figure 2-3 Examples of bit patterns From input devices To output devices Store data
BYTE • A bit pattern of lenghth 8 is called a byte • This term also has been used to measure the size of memory or other storage devices. • Example: a computer memory that can store 8 million bits of information is said to have a memory of 1 million bytes.
2.3 REPRESENTING DATA
Figure 2-4 Representing symbols using bit patterns
Table 2.1 Number of symbols and bit pattern length depends on logarithmic. It is not linear Number of Symbols--------------------- 2 4 8 16 … 128 256 … 65,536 Bit Pattern Length--------------------- 1 2 3 4 … 7 8 … 16
Examples 1 • Number of Symbols 4 00 01 10 11 • Bit Pattern Length 2
Examples 2 • Number of Symbols 8 000 001 010 011 100 101 110 111 • Bit Pattern Length 3
CODES • Code = Different sets of bit pattern designed to represent text symbols • Coding = Process of representing symbols
ASCII • American National Standards Institute (ANSI) develops American Standard Code for Information Interchange • Used 7 bits for each symbol
Features of ASCII • ASCII uses a 7-bit pattern ranging from 0000000 to 1111111 • 0000000 represent the null character (lack of character) • 1111111 represent the delete character • 31 control (nonprintable) characters • Numeric characters (0 to 9) are coded before letters • Several special printable characters • UPPERCASE A..Z) come before lowercase (a..z) • UPPERCASE and lowercase distinguished by only 1 bit. Eg: A = 1000001, a = 1100001; difference in the 6th bit from right. • Six special characters between UPPER and lowercase letters
Figure 2-5 Representation of the word “BYTE” in ASCII code
EXTENDED ASCII • To make the size of each pattern 1 byte (8 bits) • Augmented with an extra 0 at the left • Start 00000000 • Ended 01111111
EBCDIC • Extended Binary Coded Decimal Interchange Code • Used 8-bit pattern • Represent up to 256 symbols • Not used in any computers other than IBM
Unicode • Designed by coalition of hardware and software manufacturers • Uses 16 bits • Represent up to 650536 (216) symbols • Some code used for graphical and special symbols • Used by JavaTM language to represent characters. • Used by Microsoft Windows the variation of the first 256 characters
ISO • International Organization for Standardization • Designed code using 32-bit patterns • Represent up to 4 294 967 296 (232) symbols
NUMBERS • Represent number using binary system in a computer
IMAGES • Represent in a computer by two methods • Bitmap graphic • Vector graphic
Bitmap Graphic • Image is divided into a matrix of pixels (picture elements) • Each pixel is a small dot • Size of pixel = resolution • To represent color images,each colored pixel is decomposed into three color; RED, GREEN, BLUE (RGB) • For better representation of image, more memory is needed to store the image
Figure 2-7 Bitmap graphic method of a black-and-white image; used 1 bit pattern
Each pixel has three bit patterns • one to represent the intensity of the red color • one to represent the intensity of the green color • one to represent the intensity of the blue color
Figure 2-8 Representation of color pixels
Vector graphic • Does not store the bit pattern • In bitmap, if want to rescale the image, you must change the size of pixel • Vector graphic decomposed into a combination of curve and lines
AUDIO • Represent sound and music • The idea is to convert analog audio (continuous) to digital data (discrete) and used bits pattern to store
Figure 2-9 Audio representation
VIDEO • Represent of images (called frames) in time • Movie = series of frames shown one after another to create the illusiion of motion • Each images or frame is changed to a set of bit patterns and stored • In MPEG files
2.4 HEXADECIMAL NOTATION
Note: A 4-bit pattern can be representedby a hexadecimal digit,and vice versa.
Table 2.2 Hexadecimal digits Bit Pattern------------ 0000 0001 0010 0011 0100 0101 0110 0111 Hex Digit------------ 0 1 2 3 4 5 6 7 Bit Pattern------------ 1000 1001 1010 1011 1100 1101 1110 1111 Hex Digit------------ 8 9 A B C D E F
Figure 2-10 Binary to hexadecimal and hexadecimal to binary transformation
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 xCE2.
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 0s at the left to make the number of bits divisible by 4. So you have 000011100010, which is translated to x0E2.
Example 3 What is the bit pattern for x24C? Solution Write each hexadecimal digit as its equivalent bit pattern to get001001001100.
2.5 OCTAL NOTATION
Note: A 3-bit pattern can be representedby an octal digit, and vice versa.
Table 2.3 Octal digits Bit Pattern------------ 000 001 010 011 Oct Digit------------ 0 1 2 3 Bit Pattern------------ 100 101 110 111 Oct Digit------------ 4 5 6 7
Figure 2-11 Binary to octal and octal to binary transformation
Example 4 Show the octal equivalent of the bit pattern101110010. Solution Each group of 3 bits is translated to one octal digit. The equivalent is 0562,o562, or 5628.
Example 5 Show the octal equivalent of the bit pattern 1100010. Solution Divide the bit pattern into 3-bit groups (from the right). In this case, add two extra 0s at the left to make the number of bits divisible by 3. So you have 001100010, which is translated to 1428.
Example 6 What is the bit pattern for 248? Solution Write each octal digit as its equivalent bit pattern to get 010100.