42
1 Foundations of Computer Science Chapter 2 Data Representation

1 Foundations of Computer Science Chapter 2 Data Representation

Embed Size (px)

Citation preview

1

Foundations of Computer Science

Chapter 2

Data Representation

2

Outline

2.1 Data type 2.1 Data type

2.2 Data inside the computer2.2 Data inside the computer

2.3 Representing data 2.3 Representing data

2.4 Hexadecimal Notation 2.4 Hexadecimal Notation

2.5 Octal Notation2.5 Octal Notation

3

2.1Data Types

2.1Data Types

4

Different Types of Data

Data

Text Number Image Audio Video

Numbers, text, images, audio, and video are all formsof data. Computers need to process all types of data.

5

Multimedia

The computer industry uses the term“multimedia” (多媒體 ) to defineInformation that contains numbers,text, images, audio, and video.

6

2.2Data InsideThe Computer

2.2Data InsideThe Computer

7

Bit Pattern

• All data types from outside a computer 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

8

Bit Pattern

• A bit pattern of length 8 is called a byte

• Byte also been used to measure the size of memory or other storage devices

1 byte = 8 bits

1 KB = 1024 bytes

1 MB = 1024 KB

2 bytes = 16 bits

1 GB = 1024 MB

K : kilo ( 千 )M: mega (百萬 )G: giga (十億 )

210 = 1024

9

Bit Pattern

• A switch, with its two states of on and off, can represent a bit(0 or 1)

• A bit pattern is a sequence of bits that can represent a symbol

1000101010111111

10

Examples of Bit Patterns

• Data are coded (邊碼 ) when they enter a computer and decoded (解碼 ) when they are presented to the user

11

2.3Representing Data

2.3Representing Data

12

Representing Symbols Using Bit Patterns

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

Depend on how many symbols are in the set

13

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

14

Codes

• Code: different sets of bit patterns have been designed to represent text symbols– ASCII: popular code for symbols

– EBCDIC: used in IBM mainframes

– Unicode (萬國碼 ): 16-bit code, allow a greater number of symbols

– ISO: 32-bit code, allow a greater number of symbols

15

Coding

• Coding is the process of transforming data into a bit pattern

16

ASCII

• American Standard Code for Information Interchange (美國資訊交換標準碼 )

• The code be developed from the American National Standards Institute (ANSI, 美國國家標準局 )

• ASCII uses 7 bits for each symbol

27 = 128

17

Some Features of ASCII

• ASCII uses a 7-bit pattern: 0000000 ~ 1111111

• 0000000 null character; 1111111 delete character

• There are 31 control (nonprintable) characters

• The numeric characters (0~9) are coded before letters

18

Some Features of ASCII

• There are several special printable characters

• The uppercase letters (A~Z) come before the lowercase letters (a~z)

• The upper and lowercase characters are distinguished by only 1 bit. (A 1000001; a 1100001)

• There are six special characters between the upper and lowercase letters

19

Extended 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.

• Extended ASCII uses a 8-bit pattern: 00000000 ~ 01111111

20

EBCDIC

• Extended Binary Coded Decimal Interchange Code (延伸的二進位十進制交換碼 )

• EBCDIC uses 8 bits for each symbols

• Only uses in IBM mainframes

28 = 256

21

Unicode

• Unicode (萬國碼 ) be designed from a coalition of hardware and software manufacturers

• Unicode uses 16 bits and can represent up to 65,536 (216) symbols

22

ISO

• International Organization for Standardization (國際標準化組織 )

• ISO uses 32 bits and can represent up to 4,294,967,296 (232) symbols

23

Number

• Numbers are represented using the binary system

• Chapter 3

24

Images

• Images today are represented in a computer by one of two methods– Bitmap graphic (位元圖、點陣圖 )

– Vector graphic (向量圖 )

Image

Bitmap Vector

25

Bitmap Graphic

• Image is divided into a matrix of pixels (像數:圖畫元素 ), each pixel is assigned a bit pattern

• The size of the pixel depends on what is called the resolution (解析度 )

26

Representation of Color Pixels

27

Color and Gray-layer Images

Color imageRGB : 3 bytesResolution: 512 * 512 = 26,624 pixelsImage size: 512 * 512 * 3 = 79,872 bytes

Gray-layer ImageGray-layer : 1 byteResolution : 512 * 512 = 26,624 pixelsImage size: 512 * 512 * 1 = 26,624 bytes

28

Vector Graphic

• If you want to rescale the bitmap graphic image, which creates a ragged or grainy look

• An image is decomposed into a combination of curves (曲線 ) and lines (直線 )

• Each curve or line is represented by a mathematical formula (數學方程式 )

• Each time an image is drawn, the formula is reevaluated

29

Audio

Audio data are transformed to bit patterns throughsampling (取樣 ), quantization (量化 ), and coding (編碼 )

30

Video

• Video is a representation of images (called frames) in time, the combination of the images represents the video

• A movie is a series of frames shown one after another to create the illusion of motion

• Today video is normally compressed: MPEG

31

2.4HexadecimalNotation

2.4HexadecimalNotation

32

Hexadecimal Notation

• People find it difficult to manipulate bit patterns. Writing a long stream of 0s and 1s is tedious and prone to error

• A 4-bit pattern can be represented by a hexadecimal (十六進位 ) digit

33

Hexadecimal Digit

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

00000001001000110100010101100111

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

01234567

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

10001001101010111100110111101111

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

89ABCDEF

34

Binary to Hexadecimal and Hexadecimal to Binary Transformation

1111 1100 1110 0100

F C E 4

00000001001000110100010101100111

01234567

10001001101010111100110111101111

89ABCDEF

1111110011100100→ xFCE4→ XFCE4→ FCE416

35

Example

Binary Hexadecimal

1100 1110 0010 ?

000011100010 ?

? x24C

00000001001000110100010101100111

01234567

10001001101010111100110111101111

89ABCDEF

36

Example

Binary Hexadecimal

1100 1110 0010 xCE2

000011100010 x0E2

001001001100 x24C

00000001001000110100010101100111

01234567

10001001101010111100110111101111

89ABCDEF

37

Octal Notation

• A 3-bit pattern can be represented by a octal (八進位 ) digit

38

Octal Digit

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

000001010011

Octal DigitOctal Digit------------

0123

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

100101110111

Octal DigitOctal Digit------------

4567

39

Binary to Octal and Octal to Binary Transformation

1

1 7 6 3 4 4

000001010011

0123

100101110111

4567

111110011100100→ 0176344→ o176344→ 1763448

111 110 011 100 100

40

Example

Binary Octal

101110010 ?

1100010 ?

? o24

000001010011

0123

100101110111

4567

41

Example

Binary Octal

101110010 o562

1100010 o142

010110 o24

0000000100100011

0123

0100010101100111

4567

42

The End