Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / (a) Write C function revbits() which takes a single 8-bit char parameter and returns a char result by reversing the order of the bits in the char

(a) Write C function revbits() which takes a single 8-bit char parameter and returns a char result by reversing the order of the bits in the char

Computer Science

(a) Write C function revbits() which takes a single 8-bit char parameter and
returns a char result by reversing the order of the bits in the char. [4 marks]
(b) Write C function revbytes() taking two parameters and returning no result.
The first parameter is a pointer to memory containing n contiguous bytes (each
of type char), and the second is the number of bytes. The function should have
the side effect of reversing the order of the bits in the n contiguous bytes, seen
as a bitstring of length 8n. For example, the first bit of the first char should be
swapped with last bit of the last char. [6 marks]
(c) You have been assigned the following seemingly working C code, which processes
files controlling the behaviour of a system. You observe that, after obtaining
several ERR_MALFORMED errors, subsequent calls to fopen fail due to too many
files being open:
int process_file(char *name)
{ FILE *p = fopen(name, "r");
if (p == NULL) return ERR_NOTFOUND;
while (...)
{ ...
if (...) return ERR_MALFORMED;
process_one_option();
...
}
fclose(p);
return SUCCESS;
}
(i) Explain how to fix the program using facilities in C. [2 marks]
(ii) Now suppose the function above was part of a system written in C++ (but
still using the C file-processing commands such as fopen and fclose), and
that process_one_option() might raise one or more exceptions. Using
a class with a destructor, show how to fix the "too many files open" bug
above.

 

(a) Explain in general how the actions that a user takes are related to the user's
goals. Your answer should make reference to the function of perception, and to
the nature of the cognitive processing that must occur. [8 marks]
(b) Describe a class of problems for which it is not possible to formulate goals. Give
a specific example of a problem in this class, and with reference to that example,
explain how it illustrates two significant attributes of the class. [6 marks]
(c) If an interactive system has several alternative models to describe the user's
goal, how can Bayes' theorem be used to improve the system usability?

Consider the following algorithms and their associated statement counts: 1. Algorithm 1, F, = 5n - 2 2. Algorithm 2, G,, = 3n log n + 5 3. Algorithm 3, H,, = 2" + 7 4. Algorithm 4, K, = Vn+ 11 Which of the following statements is/are true? O Algorithm 1 is more efficient than Algorithm 4 O Algorithm 3 is more efficient than Algorithm 2 Algorithm 2 is more efficient than Algorithm 3 Algorithm 4 is more efficient than Algorithm 2 O Algorithm 1 is more efficient than Algorithm 2

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE