軟體實驗: c-lab7 虞台文. lab7 issues lab 7-1 on-off bits counting lab 7-2 acsii file...

14
軟軟軟 體: C-Lab7 虞虞虞

Upload: ethel-gordon

Post on 18-Jan-2018

242 views

Category:

Documents


0 download

DESCRIPTION

ACSII Table

TRANSCRIPT

Page 1: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

軟體實驗: C-Lab7

虞台文

Page 2: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

Lab7 Issues

Lab 7-1 On-Off bits counting

Lab 7-2 ACSII File Verification

Page 4: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

軟體實驗: C-Lab7

Lab 7-1

Page 5: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

Lab 7-1: On-Off Bits Counting

Write a pair of functions, bitson and bitsoff, that return the number of bits that are on and off in a file. Use the shorthand bit-manipulation operators.

Page 6: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

Lab 7-1: On-Off Bits Counting

Example:

Boy.txt

Good boy.

Good

boy.

0100 01110110 11110110 11110110 01000010 00000110 00100110 11110111 10010010 1110

on off466313654

422575234

38 34

Page 7: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

Lab 7-1: On-Off Bits Counting

Example:

Boy.txt

Good boy.

Good

boy.

0100 01110110 11110110 11110110 01000010 00000110 00100110 11110111 10010010 1110

on off466313654

422575234

38 34

There are 38 on-bits and 34 off-bits in file Boy.txt.

Page 8: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

Bit On/Off Test

01101110mask 10000000&

mask

00000000

0110111001000000&01000000

0110111000100000&00100000

0110111000010000&00000000

0110111000001000&00001000

0110111000000100&00000100

0110111000000010&00000010

0110111000000001&00000000

On

Off

On

Off

Page 9: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

bitson/bitsoff int bitson(char c)

returns number of on-bit in c

int bitsoff(char c)returns number of off-bit in c

Page 10: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

軟體實驗: C-Lab7

Lab 7-2

Page 11: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

Lab 7-2: ACSII File Verification

Write a program that verifies that every character in its

input is an ASCII character. A non-ASCII character (a

character with its high-order bit set) causes an error

message containing its octal code and position in the file

(line number and character). We can use this program to

verify that a file contains only ASCII characters before

trying to compress it with our compression program (Figure

6.2.7).

Page 13: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

Lab 7-2: ACSII File Verification

Example:Boy.txt

Good boy.

Boy.txt is an ASCII file.

Page 14: 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

Lab 7-2: ACSII File Verification

Example:Girl.txt

Good girl.She is a 美人 .Girl.txt is a non-ASCII file.

美 人AC = 10101100

= 0254

A non-ASCII char (0254) appears at position 10 of line 2.