Chapter 2 Data Representation and Storage Speaker Ying

  • Slides: 86
Download presentation
Chapter 2 Data Representation and Storage Speaker: Ying Chih Lin Department of Applied Mathematics

Chapter 2 Data Representation and Storage Speaker: Ying Chih Lin Department of Applied Mathematics National Sun Yat-sen University 2008 Fall Semester 1 Introduction to Computer Science

Outline 1. Number Systems 2. Numeric Representation 3. Floating Point 4. Data Storage 2008

Outline 1. Number Systems 2. Numeric Representation 3. Floating Point 4. Data Storage 2008 Fall Semester 2 Introduction to Computer Science

Data Types 1, 2, 3… data 2008 Fall Semester 3 01110… Introduction to Computer

Data Types 1, 2, 3… data 2008 Fall Semester 3 01110… Introduction to Computer Science

Data Manipulation v 電腦內儲存的資料只有0和1,然而我們所使用的 資料型態卻有許多種。 Word, 記事本, … ACDsee, 小畫家 Photo. Impact, Photo. Shop,

Data Manipulation v 電腦內儲存的資料只有0和1,然而我們所使用的 資料型態卻有許多種。 Word, 記事本, … ACDsee, 小畫家 Photo. Impact, Photo. Shop, … 2008 Fall Semester 4 Introduction to Computer Science

Decimal System v 十進位數字系統使用 0, 1, 2, …, 9共十個數值符號, 由這些符號組成各種數字,而每個數字中的數值 符號因為所在位置不同而代表不同數值。 23. 5210 2×

Decimal System v 十進位數字系統使用 0, 1, 2, …, 9共十個數值符號, 由這些符號組成各種數字,而每個數字中的數值 符號因為所在位置不同而代表不同數值。 23. 5210 2× 101 3× 100 5× 10 -1 5× 10 -2 MSB (most significant bit) 2008 Fall Semester LSB (least significant bit) 7 Introduction to Computer Science

數值的轉換 10進制 2進制 0 0 9 1001 11 9 1 1 10 1010 12

數值的轉換 10進制 2進制 0 0 9 1001 11 9 1 1 10 1010 12 A 2 10 2 2 11 1011 13 B 3 11 3 3 12 1100 14 C 4 100 4 4 13 1101 15 D 5 101 5 5 14 1110 16 E 6 110 6 6 15 1111 17 F 7 111 7 7 16 10000 20 10 8 1000 10 8 2008 Fall Semester 8進制 16進制 9 8進制 16進制 Introduction to Computer Science

Binary to Decimal v 1110. 11012所對應的十進位數為 14. 812510 13 12 11 00. 1 -1

Binary to Decimal v 1110. 11012所對應的十進位數為 14. 812510 13 12 11 00. 1 -1 1 -2 0 -3 1 -4 2 2 2 2 23 + 22 + 21 + 2 -2 + 2 -4 = 8 + 4 + 2 + 0. 5 + 0. 25 + 0. 0625 = 14. 8125 2008 Fall Semester 10 Introduction to Computer Science

Decimal Integer to Binary v 十進位35所對應的二進位數為 1000112 2 35 ……… 1 2 17 ………

Decimal Integer to Binary v 十進位35所對應的二進位數為 1000112 2 35 ……… 1 2 17 ……… 1 2 100011 8 ……. . 0 2 4 ……. . 0 2 2 …… 0 1 2008 Fall Semester 11 Introduction to Computer Science

Decimal Fraction to Binary v 十進位0. 8125所對應的二進位數為 0. 11012 0. 8125 × 2 1.

Decimal Fraction to Binary v 十進位0. 8125所對應的二進位數為 0. 11012 0. 8125 × 2 1. 6250 × 2 1. 2500 × 2 0. 5000 0. 1101 × 2 1. 0000 2008 Fall Semester 12 Introduction to Computer Science

Decimal Fraction to Binary v 十進位0. 45所對應的二進位數為何? 0. 45 × 2 = 0. 9

Decimal Fraction to Binary v 十進位0. 45所對應的二進位數為何? 0. 45 × 2 = 0. 9 × 2 = 1. 8 0. 8 × 2 = 1. 6 0. 6 × 2 = 1. 2 0. 2 × 2 = 0. 4 × 2 = 0. 8 2008 Fall Semester 13 0. 011100 Introduction to Computer Science

Binary & Hexadecimal 161 160 16 -1 16 -2 … d 9 d 8

Binary & Hexadecimal 161 160 16 -1 16 -2 … d 9 d 8 d 7 d 6 d 5 d 4 d 3 d 2 d 1 ‧ r 1 r 2 r 3 r 4 r 5 r 6 r 7 r 8 r 9 … 28 27 26 25 24 23 22 21 20 2008 Fall Semester 2 -1 2 -2 2 -3 2 -4 2 -5 2 -6 2 -7 2 -8 14 Introduction to Computer Science

Binary to Hexadecimal v 二進位10100011. 0111001所對應的十六進位數為 何? 1 0 0 0 1 1 1

Binary to Hexadecimal v 二進位10100011. 0111001所對應的十六進位數為 何? 1 0 0 0 1 1 1 0 0 10 A 3 7 2 2008 Fall Semester 15 Introduction to Computer Science

Hexadecimal to Binary v 十六進位1 B 5. D 8所對應的二進位數為何? 1 0 0 0 1

Hexadecimal to Binary v 十六進位1 B 5. D 8所對應的二進位數為何? 1 0 0 0 1 1 B 5. D 8 0 1. 1 1 0 0 0 1 1 2008 Fall Semester 16 Introduction to Computer Science

Outline 1. Number Systems 2. Numeric Representation 3. Floating Point 4. Data Storage 2008

Outline 1. Number Systems 2. Numeric Representation 3. Floating Point 4. Data Storage 2008 Fall Semester 18 Introduction to Computer Science

最高位元表示法(以 8位元表示整數) 位元字串 十進位數 0000 0 00000001 1 … … 位元字串 十進位數 0000 0

最高位元表示法(以 8位元表示整數) 位元字串 十進位數 0000 0 00000001 1 … … 位元字串 十進位數 0000 0 00000001 1 00000010 2 01111111 127 … … 10000000 -0 11111110 254 10000001 -1 1111 255 … … 1111 -127 2008 Fall Semester 20 Introduction to Computer Science

1補數(1’s Complement)表示法 v 一個數的負數即是將該數的 1 變 0、0 變 1,下表 顯示出以 3 bits所能表示的正負數。 2008 Fall

1補數(1’s Complement)表示法 v 一個數的負數即是將該數的 1 變 0、0 變 1,下表 顯示出以 3 bits所能表示的正負數。 2008 Fall Semester 10進位數值 1補數表示法 -3 100 -2 101 -1 110 -0 111 0 000 1 001 2 010 3 011 21 Q: 若要表示 4呢? overflow Introduction to Computer Science

2補數(2’s Complement)表示法 v 一個數的負數即是 其 1的補數值再加 1, 右表顯示出以 3 bits 所能表示的正負數。 2008 Fall Semester

2補數(2’s Complement)表示法 v 一個數的負數即是 其 1的補數值再加 1, 右表顯示出以 3 bits 所能表示的正負數。 2008 Fall Semester 10進位數值 1補數表示法 22 -4 overflow 100 -3 100 101 -2 101 110 -1 110 111 -0 111 無 0 000 1 001 2 010 3 011 Introduction to Computer Science

Practice v 用 8 bits表示,4110的二進位表示法為? § 00101001 v 用 8 bits表示,-41的1補數表示法為? § 11010110 v

Practice v 用 8 bits表示,4110的二進位表示法為? § 00101001 v 用 8 bits表示,-41的1補數表示法為? § 11010110 v 用 8 bits表示,2補數表示法 11010111,其十進位 數字為? § -41 2008 Fall Semester 25 Introduction to Computer Science

2補數表示法的兩正數相加 1 進位→ 16 0 0 0 1 0 0 +) 24 0 0

2補數表示法的兩正數相加 1 進位→ 16 0 0 0 1 0 0 +) 24 0 0 0 1 1 0 0 0 40 0 0 1 0 0 0 2008 Fall Semester 26 Introduction to Computer Science

2補數表示法的一正一負相加,且結果為正 進位→ 1 1 -16 1 1 0 0 24 0 0 0 1

2補數表示法的一正一負相加,且結果為正 進位→ 1 1 -16 1 1 0 0 24 0 0 0 1 1 0 0 0 8 0 0 1 0 0 0 +) 2008 Fall Semester 27 Introduction to Computer Science

2補數表示法的一正一負相加,且結果為負 進位→ 16 0 0 0 1 0 0 +) -24 1 1 1

2補數表示法的一正一負相加,且結果為負 進位→ 16 0 0 0 1 0 0 +) -24 1 1 1 0 0 0 -8 1 1 1 0 0 0 2008 Fall Semester 28 Introduction to Computer Science

2補數表示法的兩負數相加 進位→ 1 1 1 -16 1 1 0 0 +) -24 1 1

2補數表示法的兩負數相加 進位→ 1 1 1 -16 1 1 0 0 +) -24 1 1 1 0 0 0 -40 1 1 0 0 0 2008 Fall Semester 29 Introduction to Computer Science

2補數表示法的兩正數相加,結果超過正數 儲存範圍 進位→ 1 1 120 0 1 1 0 0 0 9 0

2補數表示法的兩正數相加,結果超過正數 儲存範圍 進位→ 1 1 120 0 1 1 0 0 0 9 0 0 1 129 1 0 0 0 1 +) overflow 2008 Fall Semester 30 Introduction to Computer Science

2補數表示法的兩負數相加,結果小於負數 儲存範圍 進位→ 1 + ) -120 1 0 0 0 -9 1 1

2補數表示法的兩負數相加,結果小於負數 儲存範圍 進位→ 1 + ) -120 1 0 0 0 -9 1 1 0 1 1 1 -129 0 1 1 1 1 overflow 2008 Fall Semester 31 Introduction to Computer Science

2補數法運算方式說明 v 假設有n bits且x是一正數,則-x的2補數表示法為 2 n-x v Ex: -41的2補數表示法為 28 -41 -) 2008 Fall

2補數法運算方式說明 v 假設有n bits且x是一正數,則-x的2補數表示法為 2 n-x v Ex: -41的2補數表示法為 28 -41 -) 2008 Fall Semester 28 1 0 0 0 0 41 0 0 1 -41 1 1 0 1 1 1 32 Introduction to Computer Science

Outline 1. Number Systems 2. Numeric Representation 3. Floating Point 4. Data Storage 2008

Outline 1. Number Systems 2. Numeric Representation 3. Floating Point 4. Data Storage 2008 Fall Semester 35 Introduction to Computer Science

浮點數表示規則 (S×(1. F)× 2 E 1) v 不同的 CPU和 FPU有其各自的浮點數表示法,但 一般較常採用 IEEE所訂定的浮點數表示法標準 (IEEE Standard

浮點數表示規則 (S×(1. F)× 2 E 1) v 不同的 CPU和 FPU有其各自的浮點數表示法,但 一般較常採用 IEEE所訂定的浮點數表示法標準 (IEEE Standard 754),分成下列二種: 單倍精準數 (single-precision) 雙倍精準數 (doubleprecision) 1 8 bits 符號 指數部份 1 11 bits 23 bits 小數部份 52 bits • 美國電機電子 程師學會(Institute of Electrical and Electronic Engineers, short to IEEE) 2008 Fall Semester 38 Introduction to Computer Science

(S×(1. F)× 2 E 1) v 12. 2510 = 1100. 012 → 1. 10001×

(S×(1. F)× 2 E 1) v 12. 2510 = 1100. 012 → 1. 10001× 23 Practice v 符號為 0 v 指數為 3,以Excess-127表示則為 130 (= 3 + 127), 轉換成 8 bits的二進位表示法為 100000102 v 小數為 100010… 0 v 完整的表示法為 010000010100010… 0 18個0 2008 Fall Semester 40 Introduction to Computer Science

(S×(1. F)× 2 E 1) v 在 IEEE-754標準下,單倍精準數 Practice 100000101000110000000是二進位多 少? v 符號為 1,是負數

(S×(1. F)× 2 E 1) v 在 IEEE-754標準下,單倍精準數 Practice 100000101000110000000是二進位多 少? v 符號為 1,是負數 v 指數部分是 510,減去 127得-122 v 小數部份是 0010100011 v 所代表的數值是-1. 0010100011× 2 -122 v 驗算網址: § http: //babbage. cs. qc. edu/IEEE-754/Decimal. html 2008 Fall Semester 41 Introduction to Computer Science

IEEE-754單倍精準數 v 0的表示法有兩個 v 最小的正數為 00001000000000000 其數值為 2 -126 (≒ 1. 175× 10 -38)

IEEE-754單倍精準數 v 0的表示法有兩個 v 最小的正數為 00001000000000000 其數值為 2 -126 (≒ 1. 175× 10 -38) v 最大的正數則為 0111111111111111 其數值為(2 -2 -23)× 2127 (≒ 3. 402× 1038) 2008 Fall Semester 43 Introduction to Computer Science

Outline 1. Number Systems 2. Numeric Representation 3. Floating Point 4. Data Storage 2008

Outline 1. Number Systems 2. Numeric Representation 3. Floating Point 4. Data Storage 2008 Fall Semester 44 Introduction to Computer Science

Common Encoding Systems v 常見的英文編碼系統有ASCII、ISO 8859和 EBCDIC。 v 常見的繁體中文編碼系統有Big 5以及CP 950 。 v 常見的簡體中文編碼系統有GB

Common Encoding Systems v 常見的英文編碼系統有ASCII、ISO 8859和 EBCDIC。 v 常見的繁體中文編碼系統有Big 5以及CP 950 。 v 常見的簡體中文編碼系統有GB 2312、GBK和GB 18030 。 v 全球統一的編碼系統Unicode。 2008 Fall Semester 47 Introduction to Computer Science

EBCDIC Code v EBCDIC Code的是 Extended Binary Code Decimal Interchange Code的縮寫,是美國 IBM公司所制定 的編碼系統,主要使用在IBM一部份大型主機上。 v

EBCDIC Code v EBCDIC Code的是 Extended Binary Code Decimal Interchange Code的縮寫,是美國 IBM公司所制定 的編碼系統,主要使用在IBM一部份大型主機上。 v EBCDIC的每一個字元是由 8個位元所組成,共有 28種組合。 2008 Fall Semester 52 Introduction to Computer Science

Big 5 Code v 雖然Big 5 -2003有19, 782個中文字,但仍有些廣泛 採用的字沒有收錄到Big 5之中。 v 常見的人名用字,如游錫“堃”、王建“煊” 、張“栢 ”芝、陶“喆”

Big 5 Code v 雖然Big 5 -2003有19, 782個中文字,但仍有些廣泛 採用的字沒有收錄到Big 5之中。 v 常見的人名用字,如游錫“堃”、王建“煊” 、張“栢 ”芝、陶“喆” 等均沒有收錄。 http: //tw. news. yahoo. com/article/url/d/a/ 080721/5/13 mgo. html http: //tw. news. yahoo. com/article/url/d/a/ 080721/17/13 mfq. html 2008 Fall Semester 55 Introduction to Computer Science

Unicode (統一碼、萬國碼) v Unicode provides a unique number for every character, § no matter

Unicode (統一碼、萬國碼) v Unicode provides a unique number for every character, § no matter what the platform, § no matter what the program, § no matter what the language. (http: //www. unicode. org) v 1991年美國資訊科技公會和 ISO國際標準化組織 合作制定 2 bytes的 Unicode 1. 0 (Universal Character Encoding),目前更新到 5. 1版,包含超過十萬個字 元。 2008 Fall Semester 57 Introduction to Computer Science

Unicode v 已發展出多種編碼方式:UTF-8、UTF-16及UTF 32等(Unicode Translation Format, UTF),分別以 8 位元、16位元及32位元為基本單元的編碼方式。 v UTF-8通行於網頁和E-mail,UTF-16為Java及 Windows所採用,而UTF-32則常見在一些Unix系 統。 v

Unicode v 已發展出多種編碼方式:UTF-8、UTF-16及UTF 32等(Unicode Translation Format, UTF),分別以 8 位元、16位元及32位元為基本單元的編碼方式。 v UTF-8通行於網頁和E-mail,UTF-16為Java及 Windows所採用,而UTF-32則常見在一些Unix系 統。 v 例如在UTF-16編碼方式中,林(6797)英(82 F 1)志 (5 FD 7)。 2008 Fall Semester 58 Introduction to Computer Science

Common Sampling Format 取樣頻率 (Hz) 解析度 (bit) 聲道 所需空間 (sec) 音質 11, 025 8

Common Sampling Format 取樣頻率 (Hz) 解析度 (bit) 聲道 所需空間 (sec) 音質 11, 025 8 Mono 11 KB 電話 22, 050 8 Mono 22 KB AM廣播 22, 050 16 Stereo 88 KB FM廣播 44, 100 16 Stereo 176 KB CD Audio • DVD標準規格的取樣率是 96 KHz 2008 Fall Semester 64 Introduction to Computer Science

Storage Space v Let the bit resolution be B and the sample rate be

Storage Space v Let the bit resolution be B and the sample rate be S. Then the bit rate R equals to the product of S and B, i. e. , we need to store R(=S×B) bits for each second of audio signals. v For example, if we have a mono audio whose sample rate is 16 KHz, bit resolution is 16 bits, sample points are 15, 716, then § The audio has 0. 98(=15, 716/16 K) seconds. § We need 31. 4 KB(15, 716× 2× 1=31, 432) space to store it. 2008 Fall Semester 65 Introduction to Computer Science

不同色彩模式之比較 v 單色 2008 Fall Semester v 256灰階 76 Introduction to Computer Science

不同色彩模式之比較 v 單色 2008 Fall Semester v 256灰階 76 Introduction to Computer Science

不同色彩模式之比較 v 16色 2008 Fall Semester v 256色 77 Introduction to Computer Science

不同色彩模式之比較 v 16色 2008 Fall Semester v 256色 77 Introduction to Computer Science

不同色彩模式之比較 v 256色 2008 Fall Semester v 全彩 78 Introduction to Computer Science

不同色彩模式之比較 v 256色 2008 Fall Semester v 全彩 78 Introduction to Computer Science

不同解析度所產生的效果 v 20 dpi 2008 Fall Semester v 100 dpi 79 Introduction to Computer

不同解析度所產生的效果 v 20 dpi 2008 Fall Semester v 100 dpi 79 Introduction to Computer Science

JPG不同壓縮比較 v 壓縮比 90、檔案大小 264 KB 2008 Fall Semester v 壓縮比 30、檔案大小 85 KB

JPG不同壓縮比較 v 壓縮比 90、檔案大小 264 KB 2008 Fall Semester v 壓縮比 30、檔案大小 85 KB 82 Introduction to Computer Science

一些碎形圖案 v http: //163. 21. 229. 21/domainweb/d 03/g 6. htm v http: //www. atlas-zone.

一些碎形圖案 v http: //163. 21. 229. 21/domainweb/d 03/g 6. htm v http: //www. atlas-zone. com/complex/fractals/index. html v http: //www. atlas-zone. com/index 0. html 2008 Fall Semester 84 Introduction to Computer Science

Storing Video v Video is a representation of images (called frames) over time. A

Storing Video v Video is a representation of images (called frames) over time. A movie consists of a series of frames shown one after another. v In other words, video is the representation of information that changes in space and in time. v So, if we know how to store an image inside a computer, we also know how to store video: each image (or frame) is transformed into a set of bit patterns and stored. The combination of the images then represents the video. 2008 Fall Semester 85 Introduction to Computer Science

See you next time ~ 2008 Fall Semester 86 Introduction to Computer Science

See you next time ~ 2008 Fall Semester 86 Introduction to Computer Science