Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification."— Presentation transcript:

1 軟體實驗: C-Lab7 虞台文

2 Lab7 Issues Lab 7-1  On-Off bits counting Lab 7-2  ACSII File Verification

3 ACSII Table

4 軟體實驗: C-Lab7 Lab 7-1

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

6 Lab 7-1: On-Off Bits Counting Example: Boy.txt Good boy. Goodboy.Goodboy. 0100 0111 0110 1111 0110 0100 0010 0000 0110 0010 0110 1111 0111 1001 0010 1110 on off 4 6 6 3 1 3 6 5 4 4 2 2 5 7 5 2 3 4 3834

7 Lab 7-1: On-Off Bits Counting Example: Boy.txt Good boy. Goodboy.Goodboy. 0100 0111 0110 1111 0110 0100 0010 0000 0110 0010 0110 1111 0111 1001 0010 1110 on off 4 6 6 3 1 3 6 5 4 4 2 2 5 7 5 2 3 4 3834 There are 38 on-bits and 34 off-bits in file Boy.txt.

8 Bit On/Off Test 01101110 mask 10000000& mask 00000000 01101110 01000000& 01101110 00100000& 01101110 00010000& 00000000 01101110 00001000& 01101110 00000100& 01101110 00000010& 01101110 00000001& 00000000 On Off On Off

9 bitson/bitsoff int bitson(char c) returns number of on-bit in c int bitsoff(char c) returns number of off-bit in c

10 軟體實驗: C-Lab7 Lab 7-2

11 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).

12 ACSII Table

13 Lab 7-2: ACSII File Verification Example: Boy.txt Good boy. Boy.txt is an ASCII file.

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


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

Similar presentations


Ads by Google