CST 8110 - M2 Review Questions

These are review questions for midterm number two.

  1. The test covers all material from class, and the entire text up until the end of Chapter section 3.1 (except section 2.7), with particular emphasis on text sections 2.5, 2.6, and 2.8.
  2. Know your Algonquin HEADER format from the 8110 Blue Book. All algorithms must use Pseudocode sufficiently detailed that C Language code could be written from it.
  3. Use as review anything from the self-check exercises, review questions, and end-of section programming exercises up to and including the end of Chapter section 3.1.
  4. Review the course note slides up to and including the slide titled Conversion of Signed Integers (#45). Pay attention to the two summary slides explaining how to convert number systems.
  5. Do lots of number conversions among the bases 2, 8, 16 and 10. Do both signed and unsigned numbers. Do 16-bit numbers, 8-bit numbers, and even a few 32-bit numbers.
  6. See the 8110 Blue Book for more details on Number Systems.
  7. See the David Bray Blue Book p.1-5 for a good summary of course material covered so far.

Sample midterm questions:

Q-1

Do the following conversions, showing exactly how they are done. Show all your work below and on the back of the previous page, as needed. The small number in parentheses after the number indicates the base of the number. All numbers and bit patterns are 16 bits wide.
Note: 162 = 256, 163 = 4,096, 164 = 216 = 65,536, 210 = 1,024

0000 0001 0010 0100(2) signed binary,
to decimal
292
1111 1110 1101 1100(2) signed binary,
to decimal
-292
1000 0001 0010 0100(2) unsigned binary,
to decimal
33,060
1000 0001 0010 0100(2) signed binary,
to hexadecimal
8124(16)
1111 1110 1101 1100(2) unsigned binary,
to octal
177334(8)

 

Q-2

Do the following conversions, showing exactly how they are done. Show all your work below and on the back of the previous page, as needed. The small number in parentheses after the number indicates the base of the number. All numbers and bit patterns are 16 bits wide.
Note: 162 = 256, 163 = 4096, 164 = 216 = 65536, 210 = 1024

10A9(16) signed hexadecimal, to decimal 4,265
EF57(16) signed hexadecimal, to decimal -4,265
A0A9(16) unsigned hexadecimal, to decimal 41,129
293(10) decimal, to binary 0000 0001 0010 0101(2)
-293(10) decimal, to binary 1111 1110 1101 1011(2)

 

Q-3

Print T in the box if the statement is True; print F if it is False. Correct answers are worth 1 mark each. No answer is worth zero marks. Incorrect answers are worth minus 1 mark (-1) each.

There are eight bytes in a bit of computer memory.

F

Each computer memory address has ten bytes.

F

CPU stands for Control Program Unit.

F

The CPU operates on numbers read from computer memory.

T

The binary decimal 0.1(2) means "1 times 2 to the power -1"

T

Signed numbers have more positive numbers than negative ones.

F

If you subtract ASCII ‘A’ from ASCII ‘C’, you get the value two.

T

The largest unsigned 8-bit integer has the value 256(10).

F

The largest signed 16-bit integer has the value 32,767(10).

T

Minus one (-1) has the value FF(16) for 8-bit and 16-bit numbers.

F

Adding one to the most negative signed number gives the most positive signed number.

F

Bit number 16 is always the sign bit of all signed numbers.

F

Signed numbers all have the sign bit set to one.

F

To negate a bit pattern, subtract it from minus one (-1).

F

ASCII characters and numbers look the same when stored as bits in computer memory.

T

FFFF(16) and 177777(8) have the same numeric value.

T

18(8) is an octal number with decimal value 16(10).

F

This is a valid pseudocode assignment statement: x + y 7

F

In a signed integer, if you invert the bit pattern for zero, you get the bit pattern for minus one.

T

Signed numbers are always negative.

F

C preprocessor directives start with a ‘%’ as the first nonblank character. F
<stdio.h> contains definitions of printf and scanf T
Constant macros must be all lower-case (small) letters F
Declarations must always precede executable statements T
Reserved words have special meanings and cannot be used for other purposes T
Identifiers may start with letters or digits F
PI is a standard identifier defined in <stdio.h> F
2 + 5 = sum; is a C language assignment statement that puts 7 into "sum" F
printf("%f%f%f",2.3); outputs the value 2.3 on the screen three times F
printf("Hello\nThere\n"); prints "Hello There " on the screen with blanks F
(* this is a C language comment *) F
The magnitude of m % n is always less than n T
m % n can never be zero F
Dividing 100 by 0 causes overflow and all the bits are turned on F
If x is 2, then printf("%d", 3x); prints the number 6 on the screen F

 

Q-4

Pick appropriate numeric representations, either Integer or Float, for the various quantities and measurements given below, and justify your answers on the given lines.

Assume that integers are 16-bit signed values, and floating-point numbers have the standard C-language float properties. Enter in the box the word Integer or Float for the storage type that is most appropriate to store the given measurements, and explain why.

 

  The number of pencils in your desk at home.
  Your body temperature, in Celsius, to 3 significant digits.
  The exact price of ten boxes of Macaroni and Cheese Dinner.
  The speed of a car in kilometres per hour.

 

Integer/Float? Explain your choice here…

Integer

It is a count of a small number of integral items.

Float

The measurement requires a decimal point.

Float

Money requires decimal points.

Integer

It is a count of a small number of integral items.

 

Q-5

Give the answers to the following questions in decimal numbers.
For partial marks in answering these questions, show below how you arrived at the answer.

What is the largest unsigned value that can be stored in 12 bits? 4,095 = 212-1
What is the smallest signed value that can be stored in 12 bits? -2,048 = -211
What is the largest signed value that can be stored in 12 bits? 2,047 = +211-1

 

Q-6

What is the value of the following C language expression? 25 % 18 / 2 + 4 = 7

 

Q-7

Show how the floating-point number -99.682 would appear when printed using each of the following output formats. Show leading and/or trailing blanks in the output of formatted numbers using a capital ‘X’ character in place of the blanks that would normally appear, e.g. XXX98.6XX

 

%8.4f -99.6820
%8.3f X-99.682
%8.2f XX-99.68
%8.1f XXX-99.7
%8.0f XXXX-100
%.1f -99.7

 

Q-8

Do the following conversions. The small number in parentheses after the number indicates the base of the number. All numbers and bit patterns are 16 bits wide.
Note: 162 = 256, 163 = 4,096, 164 = 216 = 65,536, 210 = 1,024

345(10) decimal to hexadecimal  
0000 0111 1000 0011(2) signed binary to decimal  
-77(10) decimal to binary  
FFA5(16) signed hexadecimal to decimal  
AAA4(16) unsigned hexadecimal to decimal  

 

Q-9

Write complete C language declarations for the variables used in the scanf function call below:

scanf( "%x %u %d %f", &One, &Two, &Three, &Four );

One:  
Two:  
Three:  
Four: