Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. When we call the fopen function to open a file and we specific \"rb\" in the

ID: 3775272 • Letter: 1

Question

1.     When we call the fopen function to open a file and we specific "rb" in the second parameter, which ONE of the following best describes what we're attempting to do?

a. Create a new file, and use the fwrite function to write raw bytes into the file.

b. Open an existing file for reading, and use the fread function to read raw bytes from the file.

c. Open an existing file for reading, and use the fscanf function to read human-readable text from the file.

d. Create a new file, and use the fprintf function to write human-readable text into the file.

2 Which of the following are TRUE statements about why we might use bit manipulation in C? Select ALL correct responses.

a. Packing information into bits can save file storage space.

b. Packing information into bits can save memory space while the program is running.

c. Packing information into bits can reduce transmission time of data over a network.

d. Hardware devices often provide or receive information as bits packed within bytes.

e. Error detection and correction algorithms often use bit manipulation.

3. Assuming x, y, and z are all integer variables that have been initialized, which ONE of the following statements will compute the "bitwise AND" of the values in x and y, and store the result in z?

a. z = x & y;

b.z = x && y;

c. z = &x && &y;

d. z &= x & y;

4. Assuming x contains the binary value 10101010 and y contains the binary value 11001100, which ONE of the following statements is the value of the expression (x ^ y)?

a. 11101110

b. 10101010

c. 11001100

d. 11111111

e. 01100110

5. Assuming x contains the binary value 10101010 and y contains the binary value 11001100, which ONE of the following statements is the value of the expression (x | y)?

a. 10101010

b. 11001100

c. 11111111

d. 11101110

e. 01100110

6. If x contains the integer decimal value 42, which of the following are TRUE statements? Select ALL correct responses.

a. The binary (base 2) representation of x is 101010.

b. The hexadecimal representation of x is 2A (written in C as 0x2A).

c. The value of the expression (x ^ x) is 1.

d. The decimal value of the expression (x >> 1) is 21.

e. The binary value of the expression (x << 2) is 10101000.

7. In our C environment, which ONE of the following best describes how a double is represented internally?

a. One sign bit, 8 exponent bits, and 23 mantissa bits, for a total of 32 bits.

b. An integer value represented in two's-complement format.

c. One sign bit, 11 exponent bits, and 52 mantissa bits, for a total of 64 bits.

d. An integer value represented in one's-complement format.

e. An integer value, where the leftmost bit is the sign, and the remaining 31 bits represent the magnitude.

8. Assuming we have a large collection of very small double values and very large double values, and we need write a program to compute the sum of all of these values, which ONE of the following statements is FALSE?

a. No matter what order we add the numbers in (e.g., smallest to largest, largest to smallest, random order, etc.), we will always end up with the exact same sum.

b. Adding the largest numbers first and then adding in the smallest numbers can give us a different result from adding the smallest numbers first and then adding in the largest.

c. Because we have a fixed number of significant digits, our computations can be affected by round-off error.

9. Which ONE of the following mathematics expressions correctly describes the number of unique binary values we can represent using a sequence of N bits?

a. 2(N-1)

b. 2N
c. 2N-1

d. N2

e.2·N

f. N

10. Which of the following are TRUE statements about the parts of a C compiler? Select ALL correct responses.

a. The preprocessor runs first, pulling in #include files, substituting #define symbols, and stripping out comments.

b.The code generator needs to have deep knowledge of the machine instructions available on the CPU hardware for which the program is being compiled.

c.The parser knows the rules of C, and issues error messages when we break those rules.

d. The lexical analyzer runs as the very last step of the compilation process.

e. The preprocessor #define macros can be dangerous because of operator precedence rules and expression side-effects.

Explanation / Answer

Answer

2.

The correct reponses are:

b. Packing information into bits can save memory space while the program is running.

d. Hardware devices often provide or receive information as bits packed within bytes.

e. Error detection and correction algorithms often use bit manipulation.

3.

The instructions which will compute bitwise AND and store the result are:

a. z = x & y;

d. z &= x & y;

4.

x = 10101010

y = 11001100

x ^ y = 01100110

So, e. 01100110 is the answer

5.

x = 10101010

y = 11001100

x | y = 11101110

So, d. 11101110 is the answer