Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer....

41
Chapter 2 Data Representation

Transcript of Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer....

Page 1: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Chapter 2

DataRepresentation

Page 2: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Define Define data typesdata types..

Visualize Visualize how data are stored inside a computerhow data are stored inside a computer..

Understand the differences between Understand the differences between texttext, , numbersnumbers, , imagesimages,,videovideo, and , and audioaudio..

After reading this chapter, the reader should After reading this chapter, the reader should be able to:be able to:

OOBJECTIVESBJECTIVES

Work with Work with hexadecimalhexadecimal and octal and octal notationsnotations..

Page 3: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

DATA TYPESDATA TYPESDATA TYPESDATA TYPES

2.12.1

Page 4: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Figure 2-1Different types of data

Page 5: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

The computer industry uses the termThe computer industry uses the term““multimediamultimedia” to define information ” to define information

that contains numbers, text, images, that contains numbers, text, images, audio, and video.audio, and video.

Note:Note:

Page 6: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

DATA INSIDEDATA INSIDETHE COMPUTERTHE COMPUTER

DATA INSIDEDATA INSIDETHE COMPUTERTHE COMPUTER

2.22.2

Page 7: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Figure 2-2

• Bit pattern - a string of bits

• Bit (Binary Digit)- is the smallest unit of data that can be stored in a computer; it is either 0 or 1.

Page 8: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Figure 2-3 Examples of bit patterns

• Computer memory does not know that type of data a stored bit pattern represents. It just stores the data as bit patterns.

• It is the responsibility of I/O devices or programs to interpret a bit pattern as a number, text, or some other type of data.

Page 9: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

DataData are are codedcoded when they when they enter a computerenter a computer and and decodeddecoded when they are when they are presented to the presented to the useruser..

Page 10: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

REPRESENTINGREPRESENTINGDATADATA

REPRESENTINGREPRESENTINGDATADATA

2.32.3

Page 11: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

TEXTTEXT

A piece of text in any language is a sequence of symbols used to represent an idea in that language.

Symbols in English language :– Uppercase letters (A~Z)– Lowercase letters (a~z)– Numeric characters (0~9)– Punctuations (. , : ; …)

Page 12: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Figure 2-4

Representing symbols using bit patterns

Page 13: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Bit Pattern LengthBit Pattern Length

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

It depends on how many symbols are in the set.

Page 14: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Table 2.1 Number of symbols and bit pattern lengthTable 2.1 Number of symbols and bit pattern length

Number of SymbolsNumber of Symbols---------------------

248

16…

128256…

65,536

Bit Pattern LengthBit Pattern Length---------------------

1234…

78…

16

Page 15: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

CodesCodes

Code –Set of bit patterns designed to represent text symbols.

Coding –the process of representing symbols

Page 16: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Figure 2-5

Representation of the word “BYTE” in ASCII code

ASCII code – developed by ANSIuses 7 bits for each symbol.

This means 128 different symbols can be defined by this code.

Page 17: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Extended ASCIIExtended ASCII

To make the size of each pattern 1 byte (8 bits), the ASCII bit patterns are augmented with an extra 0 at the left.

Each pattern can easily fit into 1 byte of memory.

Page 18: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

EBCDIC & UnicodeEBCDIC & Unicode

EBCDIC- – Developed by IBM– Used in IBM mainframe computers.

Unicode –– 16 bits (65536 symbols)– Different sections of the code are allocated

to symbols from different languages in the world.

Page 19: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Figure 2-6

Image representation methods

Page 20: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Bitmap GraphicBitmap Graphic

A image is divided into a matrix of pixels, where each pixel is a small dot.– More pixels – Better representation of image – Better resolution – More memory

Each pixel is assigned a bit pattern.

The size and the value of the pattern depend on the image.

Page 21: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Figure 2-7Bitmap graphic method of a

black-and-white image

Page 22: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Figure 2-8 Representation of color pixels

Color imageEach pixel is decomposed into 3 primary colors:

red, green and blue. (RGB)The intensity of each color is measured, and a bit

pattern (8 bits) is assigned.

Page 23: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

ResolutionResolution The term is most often used to describe monitors,

printers, and bit-mapped graphic images. Dot-matrix and laser printers,

the resolution indicates the number of dots per inch. For example, a 300-dpi (dots per inch) printer is one that is capable of printing 300 distinct dots in a line 1 inch long. This means it can print 90,000 dots per square inch.

Graphics monitors, the screen resolution signifies the number of dots (pixels) on the entire screen. For example, a 640-by-480 pixel screen is capable of displaying 640 distinct dots on each of 480 lines, or about 300,000 pixels.

Page 24: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Vector GraphicVector Graphic

A image is decomposed into a combination of curves and lines.

Each curve or line is represented by a mathematical formula.

Page 25: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

AudioAudio Audio is a representation of sound or music. Audio is by nature analog data. It is continuous, not discrete. Audio is converted to digital data and stored

in bit patterns.1. Sampling

2. Quantization

3. Coding

4. Stored

Page 26: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Figure 2-9Audio representation

Page 27: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

VideoVideo Video is a representation of images (frames)

in time. A movie is a series of frames shown one

after another to create the illusion of motion. Today video is normally compressed.

Page 28: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

HEXADECIMALHEXADECIMALNOTATIONNOTATION

HEXADECIMALHEXADECIMALNOTATIONNOTATION

2.42.4

Page 29: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

A 4-bit pattern can be representedA 4-bit pattern can be representedby a by a hexadecimal digithexadecimal digit,,

and vice versa.and vice versa.

NoteNote::

Page 30: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Table 2.2 Hexadecimal digitsTable 2.2 Hexadecimal digits

Bit PatternBit Pattern------------

00000001001000110100010101100111

Hex DigitHex Digit------------

01234567

Bit PatternBit Pattern------------

10001001101010111100110111101111

Hex DigitHex Digit------------

89ABCDEF

Page 31: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Figure 2-10

Binary to Hexadecimal and Hexadecimal to Binary transformation

Page 32: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Example 1Example 1

Show the hexadecimal equivalent of the bit pattern 1100 1110 0010.

SolutionSolution

Each group of Each group of 4 bits4 bits is translated to is translated to one hexadecimal digitone hexadecimal digit. . The equivalent is xCE2.The equivalent is xCE2.

Page 33: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

ExampleExample 22

Show the hexadecimal equivalent of the bit pattern 00 1110 0010.

SolutionSolution

Divide the bit pattern into 4-bit groups Divide the bit pattern into 4-bit groups ((from the rightfrom the right)). . In this case, add In this case, add two extra 0stwo extra 0s at the left to make at the left to make the number of bits divisible by 4. the number of bits divisible by 4. So you have So you have 000000 1110 0010, 00 1110 0010, which is translated to which is translated to x0E2x0E2..

Page 34: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Example 3Example 3

What is the bit pattern for x24C?

SolutionSolution

Write each hexadecimal digit as Write each hexadecimal digit as its equivalent bit pattern to getits equivalent bit pattern to get0010 0100 1100.0010 0100 1100.

Page 35: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

OCTALOCTALNOTATIONNOTATION

OCTALOCTALNOTATIONNOTATION

2.52.5

Page 36: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

A A 3-bit pattern3-bit pattern can be represented can be representedby an by an octal digitoctal digit, , and vice versa.and vice versa.

NoteNote::

Page 37: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Table 2.3 Octal digitsTable 2.3 Octal digits

Bit PatternBit Pattern------------

000001010011

Oct DigitOct Digit------------

0123

Bit PatternBit Pattern------------

100101110111

Oct DigitOct Digit------------

4567

Page 38: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Figure 2-11

Binary to Octal and Octal to Binary transformation

Page 39: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Example 4Example 4

Show the octal equivalent of the bit pattern 101 110 010.

SolutionSolution

Each group of 3 bitsEach group of 3 bits is translated to is translated to one octal digit. one octal digit. The equivalent is The equivalent is 05620562, , o562o562, or , or 56256288

..

Page 40: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Example 5Example 5

Show the octal equivalent of the bit pattern 1 100 010.

SolutionSolution

Divide the bit pattern into Divide the bit pattern into 3-bit groups3-bit groups ((from the rightfrom the right)). . In this case, add In this case, add two extra 0stwo extra 0s at the left to make at the left to make the number of bits divisible by 3. the number of bits divisible by 3. So you have So you have 00001 100 010, which is translated to 1 100 010, which is translated to 14214288 ..

Page 41: Chapter 2 Data Representation. Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images,

Example 6Example 6

What is the bit pattern for 248?

SolutionSolution

Write each octal digit as its Write each octal digit as its equivalent bit pattern to get equivalent bit pattern to get 010010 100100..