Top Banner
1 Foundations of Computer Science Chapter 2 Data Representation
42

1 Foundations of Computer Science Chapter 2 Data Representation.

Dec 30, 2015

Download

Documents

Mark Gardner
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Foundations of Computer Science Chapter 2 Data Representation.

1

Foundations of Computer Science

Chapter 2

Data Representation

Page 2: 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

Page 3: 1 Foundations of Computer Science Chapter 2 Data Representation.

3

2.1Data Types

2.1Data Types

Page 4: 1 Foundations of Computer Science Chapter 2 Data Representation.

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.

Page 5: 1 Foundations of Computer Science Chapter 2 Data Representation.

5

Multimedia

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

Page 6: 1 Foundations of Computer Science Chapter 2 Data Representation.

6

2.2Data InsideThe Computer

2.2Data InsideThe Computer

Page 7: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 8: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 9: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 10: 1 Foundations of Computer Science Chapter 2 Data Representation.

10

Examples of Bit Patterns

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

Page 11: 1 Foundations of Computer Science Chapter 2 Data Representation.

11

2.3Representing Data

2.3Representing Data

Page 12: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 13: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 14: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 15: 1 Foundations of Computer Science Chapter 2 Data Representation.

15

Coding

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

Page 16: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 17: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 18: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 19: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 20: 1 Foundations of Computer Science Chapter 2 Data Representation.

20

EBCDIC

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

• EBCDIC uses 8 bits for each symbols

• Only uses in IBM mainframes

28 = 256

Page 21: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 22: 1 Foundations of Computer Science Chapter 2 Data Representation.

22

ISO

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

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

Page 23: 1 Foundations of Computer Science Chapter 2 Data Representation.

23

Number

• Numbers are represented using the binary system

• Chapter 3

Page 24: 1 Foundations of Computer Science Chapter 2 Data Representation.

24

Images

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

– Vector graphic (向量圖 )

Image

Bitmap Vector

Page 25: 1 Foundations of Computer Science Chapter 2 Data Representation.

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 (解析度 )

Page 26: 1 Foundations of Computer Science Chapter 2 Data Representation.

26

Representation of Color Pixels

Page 27: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 28: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 29: 1 Foundations of Computer Science Chapter 2 Data Representation.

29

Audio

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

Page 30: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 31: 1 Foundations of Computer Science Chapter 2 Data Representation.

31

2.4HexadecimalNotation

2.4HexadecimalNotation

Page 32: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 33: 1 Foundations of Computer Science Chapter 2 Data Representation.

33

Hexadecimal Digit

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

00000001001000110100010101100111

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

01234567

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

10001001101010111100110111101111

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

89ABCDEF

Page 34: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 35: 1 Foundations of Computer Science Chapter 2 Data Representation.

35

Example

Binary Hexadecimal

1100 1110 0010 ?

000011100010 ?

? x24C

00000001001000110100010101100111

01234567

10001001101010111100110111101111

89ABCDEF

Page 36: 1 Foundations of Computer Science Chapter 2 Data Representation.

36

Example

Binary Hexadecimal

1100 1110 0010 xCE2

000011100010 x0E2

001001001100 x24C

00000001001000110100010101100111

01234567

10001001101010111100110111101111

89ABCDEF

Page 37: 1 Foundations of Computer Science Chapter 2 Data Representation.

37

Octal Notation

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

Page 38: 1 Foundations of Computer Science Chapter 2 Data Representation.

38

Octal Digit

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

000001010011

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

0123

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

100101110111

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

4567

Page 39: 1 Foundations of Computer Science Chapter 2 Data Representation.

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

Page 40: 1 Foundations of Computer Science Chapter 2 Data Representation.

40

Example

Binary Octal

101110010 ?

1100010 ?

? o24

000001010011

0123

100101110111

4567

Page 41: 1 Foundations of Computer Science Chapter 2 Data Representation.

41

Example

Binary Octal

101110010 o562

1100010 o142

010110 o24

0000000100100011

0123

0100010101100111

4567

Page 42: 1 Foundations of Computer Science Chapter 2 Data Representation.

42

The End