軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1 On-Off bits counting Lab 7-2 ACSII File...
-
Upload
ethel-gordon -
Category
Documents
-
view
248 -
download
0
description
Transcript of 軟體實驗: C-Lab7 虞台文. Lab7 Issues Lab 7-1 On-Off bits counting Lab 7-2 ACSII File...
軟體實驗: C-Lab7
虞台文
Lab7 Issues
Lab 7-1 On-Off bits counting
Lab 7-2 ACSII File Verification
軟體實驗: C-Lab7
Lab 7-1
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.
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
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.
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
bitson/bitsoff int bitson(char c)
returns number of on-bit in c
int bitsoff(char c)returns number of off-bit in c
軟體實驗: C-Lab7
Lab 7-2
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).
Lab 7-2: ACSII File Verification
Example:Boy.txt
Good boy.
Boy.txt is an ASCII file.
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.