Week 03 Weekly Test Questions
Test Conditions
These questions must be completed under self-administered exam-like conditions. You must time the test yourself and ensure you comply with the conditions below.
- You may complete this test in CSE labs or elsewhere using your own machine.
- You may complete this test at any time before Wednesday 01 January 00:00.
- The maximum time allowed for this test is 1 hour + 5 minutes reading time.
- You may first use 5 minutes to read the questions (no typing).
- You must then complete the test within 1 hour and submit your answers with give.
- You must complete the questions alone: you can not get help in any way from any person.
- You can not access your previous answers to lab or tut questions.
- You can not access web pages or use the internet in any way.
- You can not access books, notes or other written or online materials.
- You can not access your own files, programs, code ...
- You can not access COMP1521 course materials, except for language documentation linked below.
You may access this language documentation while attempting this test:
You may also access manual entries (the man
command).
Any violation of the test conditions will results in a mark of zero for the entire weekly test component.
Set up for the test by creating a new directory called
test03
, changing to this directory, and fetching the
provided code by running these commands:
mkdir test03 cd test03 1521 fetch test03
Or, if you're not working on CSE, you can download the provided code as a zip file or a tar file.
You should not write any code. Test in Progress — working time You have just over minutes left in the test. Test Complete! Your time for this test has finished. You may submit your work. You may choose to keep working, but you should not submit further work. You should reflect on how you went in this hour, and discuss with your tutor if you have concerns.
weekly test question:
Swap the bytes of a 16-bit Value
Your task is to add code to this function in short_swap.c:
// given uint16_t value return the value with its bytes swapped
uint16_t short_swap(uint16_t value) {
// PUT YOUR CODE HERE
return 42;
}
Add code to the function short_swap
so that, given a
uint16_t
value, it returns the value with its bytes
swapped. You should use bitwise operators to do this.
For example:
./short_swap 0x1234 short_swap(0x1234) returned 0x3412 ./short_swap 0xfade short_swap(0xfade) returned 0xdefa ./short_swap 0x01080 short_swap(0x1080) returned 0x8010
Use make(1) to build your code:
make # or 'make short_swap'
When you think your program is working you can
autotest
to run some simple automated tests:
1521 autotest short_swapWhen you are finished working on this exercise you must submit your work by running give:
give cs1521 test03_short_swap short_swap.c
weekly test question:
Count the 1 Bits of a 64-bit Value
Your task is to add code to this function in bit_count.c:
// return how many 1 bits value contains
int bit_count(uint64_t value) {
// PUT YOUR CODE HERE
return 42;
}
Add code to the function bit_count
so that, given a
uint64_t
value, it returns how many 1 bits it
contains. You should use bitwise operators to do this.
For example:
./bit_count 0x123456789abcdef0 bit_count(0x123456789abcdef0) returned 32 ./bit_count 0xffffffffffffffff bit_count(0xffffffffffffffff) returned 64 ./bit_count 0x0000000000000000 bit_count(0x0000000000000000) returned 0 ./bit_count 0x0000000400000000 bit_count(0x0000000400000000) returned 1 ./bit_count 0x8000000000000001 bit_count(0x8000000000000001) returned 2
Use make(1) to build your code:
make # or 'make bit_count'
When you think your program is working you can
autotest
to run some simple automated tests:
1521 autotest bit_countWhen you are finished working on this exercise you must submit your work by running give:
give cs1521 test03_bit_count bit_count.c
weekly test question:
Swap Pairs of Bits of a 64-bit Value
Your task is to add code to this function in bit_swap.c:
// return value with pairs of bits swapped
uint64_t bit_swap(uint64_t value) {
// PUT YOUR CODE HERE
return 42;
}
Add code to the function bit_swap
so that, given a
uint64_t
value, it returns the same value with each
pair of bits swapped: bit 0 should be swapped with bit 1, bit 2
should be swapped with bit 3, bit 4 should be swapped with bit 5,
and so on. You should use bitwise operators to do this.
For example:
./bit_swap 0x1111111111111111 bit_swap(0x1111111111111111) returned 0x2222222222222222 ./bit_swap 0x1111888855553333 bit_swap(0x1111888855553333) returned 0x22224444aaaa3333 ./bit_swap 0x0000000400000000 bit_swap(0x0000000400000000) returned 0x0000000800000000 ./bit_swap 0x8000000000000001 bit_swap(0x8000000000000001) returned 0x4000000000000002 ./bit_swap 0x123456789abcdef0 bit_swap(0x123456789abcdef0) returned 0x2138a9b4657cedf0
Use make(1) to build your code:
make # or 'make bit_swap'
When you think your program is working you can
autotest
to run some simple automated tests:
1521 autotest bit_swapWhen you are finished working on this exercise you must submit your work by running give:
give cs1521 test03_bit_swap bit_swap.c
Submission
You can run give multiple times. Only your last submission will be marked.
Don't submit any exercises you haven't attempted.
If you are working at home, you may find it more convenient to upload your work via give's web interface.
Remember you have until Wednesday 01 January 00:00 to complete this test.
Automarking will be run by the lecturer several days after the
submission deadline for the test, using test cases that you haven't
seen: different to the test cases
autotest
runs for you.
(Hint: do your own testing as well as running
autotest
)
Test Marks
After automarking is run by the lecturer you can view it here the resulting mark will also be available via via give's web interface or by running this command on a CSE machine:
1521 classrun -sturec
The test exercises for each week are worth in total 1 marks.
The best 6 of your 8 test marks for weeks 3-10 will be summed to give you a mark out of 9.