CSCE 230 Computer Organization
Spring 2004
Steve Goddard
50
points: This is a “simple” C programming problem to help familiarize you with
some of the basic C language functions and the binary representation of
numbers. The requirements are simple:
a.
Your C executable program will be named BitPattern.
b.
No input parameters on the command line will be required.
c.
No C++ functions are to be used (e.g. cout, cin). Use C functions instead (e.g. printf,
scanf).
d.
The program will print the following to standard output
(stdout), adhering to the format as shown.
Binary representations for
the following positive integers are as follows:
1 = 00000000
00000000 00000000 00000001
175
= 00000000 00000000
00000000 10101111
143165576
= 00001000 10001000
10001000 10001000
e.
To accomplish the above, a function printBits(int x)
should be designed and coded, which prints the line x
= yyyyyyyy yyyyyyyy
yyyyyyyy yyyyyyyy , to standard output (stdout)
where x is a positive integer and the series
of y’s represents the binary bit pattern of
x. Display the most
significant bit to the left in the series.
The format must include the right justification of the integers, 2
spaces between the integer and the equals sign, 2 spaces between the equals
sign and the MSB of the bit pattern, and then 2 spaces between each group of 8
bits.
f.
After the display (as described in item d) has been printed
to screen, then the following 3 line prompt should be displayed:
Enter a positive integer
in the range of 1 to
2147483647
or
Enter 0 to quit. ŕ
One empty line should separate the last line of the initial display and the first line of the three-line prompt. If 0 is entered, then the program should terminate. If an integer in the range of 1 to 2,4147,483,647 is entered, than the bit pattern for that integer is printed to stdout after which the above prompt is again displayed with one empty line between the bit pattern and the prompt. The format of the print out should match the first three bit patterns displayed. An example of the complete format is given below.
Binary representations for
the following positive integers are as follows:
1 = 00000000
00000000 00000000 00000001
175
= 00000000 00000000
00000000 10101111
143165576
= 00001000 10001000
10001000 10001000
Enter a positive integer
in the range of 1 to
2147483647
or
Enter 0 to quit. ŕ
127
127 =
00000000 00000000 00000000
01111111
Enter a positive integer
in the range of 1 to
2147483647
or
Enter 0 to quit. ŕ 0
g.
Version 3.0, dated September 3, 2003, of the JDEHP coding
standard must be followed. This version
is now available from the course Web site.
h.
Create and turn in a Makefile that will build your
executable from your source file(s).
The problem will be scored at follows:
Make
File 5% (2.5
pts)
README.TXT
file
5% (2.5 pts)
Program correctness 50% (25 pts)
Quality of design/readability 20% (10 pts)
In-line documentation/coding standard 20%
(10 pts)
No analysis report is required, but a README.TXT file is required to explain program compilation and execution. Program correctness will be determined by the correct functionality of the program as well as adherence to format specifications.