1. Due Date
HW 2 due: : Due by 11:59 pm, Friday, February 9, 2024
2. About Written Assignments
Written assignments are not worth as much as lab assignments, but are designed to give you some extra practice on lecture material and on some of the type of questions you may see on course exams.
You can work with a group of three to four students (total, including yourself) on homework assignments in this class. Please read this information about working in your study groups and tips for working on joint homework assignments with your study group: About CS31 Homework and Study group.
You will submit just one joint solution by your group by turning it in on Gradescope on the day it is due. Here’s a tutorial on how to turn in Group Homeworks on gradescope. If you are unsure of how to make this work, you can also just bring it in to the start of class. Make sure that the names of all the students in your group are included in the group submission, and be sure to take turns in different group roles each HW assignment (see the link above for more information).
3. The Assignment
Answer the questions below showing your work and/or explaining your answer.
-
For these questions, if a question specifies a number of bits, your answer should be in a corresponding number of digits. For example, if the question asks to add 4 bit values together your answer should be a 4 bit value, not a 64 bit one.
-
You can assume that two’s complement is used for signed values, which makes the highest-order bit an indication of the value’s sign. For example,
1000
should be interpreted as negative as a 4-bit signed value, but positive as an 8-bit signed value(00001000)
. -
For these questions you will be graded on showing how you applied the operation or conversion method we described in class: you must show your work or explain how you got the result to receive credit.
4. Questions
-
What is the largest positive value that can be represented with an unsigned 8 bit number? Explain.
-
What is the largest positive value that can be represented with a 2’s complement 8 bit number? Explain.
-
Convert the unsigned 8 bit binary value
0b10100110
to decimal. Show your work. -
Convert the signed 8 bit binary value
0b10100110
to decimal. Show your work. -
For the following 8 bit binary values (show your work):
value 1: 01011101 value 2: 01100101
-
Add the binary values together. What is the decimal representation of the result if it is interpreted as a signed 8 bit value?
-
For the same addition, what is the decimal representation of the result if it is interpreted as an unsigned 8 bit value?
-
What is the binary representation of the result of adding
value1
andvalue2
together? Does this result in overflow for signed or unsigned interpretations of the values, why or why not? -
What is the binary representation of the result of subtracting the
value2
fromvalue1
? Does this result in overflow for signed or unsigned interpretations of the values, why or why not?
-
-
Convert the following 2-byte binary numbers to hexadecimal, indicating how each part is converted (the binary values are shown with spaces between each 4 digits just to make them easier to read):
-
0000 0110 0001 1111
-
1100 0101 1110 0101
-
1010 0111 1101 0110
-
-
Convert the following hexadecimal numbers to binary, indicating how you converted each digit:
-
0x23
-
0x852
-
0xc1a6
-
0xefab
-
-
Convert the following decimal values to 8 bit (2’s complement) binary and additionally convert the binary results to hexadecimal. Show your work:
-
12
-
-36
-
123
-
-123
-
-
Given the following 4 bit binary values, show the results of each bit-wise operation, showing both the binary and decimal result value for each (list the unsigned decimal value). Show your work and the results of each bitwise operation:
-
0110 | ~(1010)
-
~(0110 | 1010)
-
0111 & ~(1001)
-
(1010 | 0000) & 1111
-
0011 ^ 1110
-
0111 << 2
-
0111 >> 2
-
5. Answer write-up and gradescope
For most of the problems on this assignment we will give you the option of entering your answer directly into gradescope, or uploading an image or a .pdf file of your answer. As always, please ensure any handwritten answers are legible and that the uploaded file is readable. You likely want to do a mix, as certainly for some of these, a handwritten answer and image upload will likely be easier.
If you enter you answer directly in gradescope, we suggest you first type them into an text file, and then copy and paste into gradescope (just in case you forget to save your answer, you don’t want to lose it). For example, I might create a file in vim into which I’ll enter my answers:
vim hw2_soln.txt
Gradescope also does not support much special formatting of answers. As a result, if you enter your answers (vs. upload a file), please follow these conventions for representing specific numeric formats:
-
for superscript use
^
, so2^4
is 2 to the fourth power. -
for subscripts use a number after a variable, so
X3
is X sub 3. -
for hexadecimal values, use the
0x
prefix, so0x123a
is hexadecimal value 123a. -
for binary values, use the
0b
prefix, so 0b101010 is binary value 101010. -
for decimal values, use no prefix, so 10101 is decimal value 10,101.
Your answer should include all 8 digits (or the number of digest specified in the problem. For the example, your answer should be represented like this (and should also include showing your work for how you performed the addition):
00010101
+ 00000010
----------
= 00010111
6. Submitting Your Solution
You will submit your solution on gradescope.
In general, for some homework questions you may enter your answer directly in gradescope and for others you may upload an image or .pdf file with your solution in gradescope. Sometimes we give you an option to do either.
6.1. Creating electronic files to upload in gradescope
There are many different ways to create an electronic file version to upload, some include:
-
Hand write your answer on paper, and upload a photo image from your smartphone or tablet.
-
Use some software to write-up your answer (googledocs, powerpoint, …) and create a .pdf version to upload (either screenshot or using a save as pdf feature of the software you are using).
-
print out the .pdf of the assignment, hand write your answers to a problem, take a photo with a smartphone or tablet of your answer to each part and upload it in gradescope.
On exams, you will also do file upload of solutions in gradescope. The most expedient way to do this is by handwriting and image upload, so we recommend you practice that with some of your homework file uploads prior to an exam.
For handwritten answers, make sure your writing is legible. For any image you upload check the uploaded file with your answer and make sure it is readable and includes your full answer. If not, take another photo and try again.