cs-3843: add HW3
This commit is contained in:
parent
2dfc1ab3fe
commit
6c291be12f
123
Fall-2024/CS-3843/Assignments/HW-3/Assignment.typ
Normal file
123
Fall-2024/CS-3843/Assignments/HW-3/Assignment.typ
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
#import "@preview/tablex:0.0.4": tablex, rowspanx, colspanx, hlinex, vlinex
|
||||||
|
|
||||||
|
#show link: set text(blue)
|
||||||
|
#set text(font: "Calibri")
|
||||||
|
#show raw: set text(font: "Fira Code")
|
||||||
|
|
||||||
|
#set page(margin: (x: .25in, y: .25in))
|
||||||
|
#let solve(solution) = [
|
||||||
|
#let solution = align(
|
||||||
|
center,
|
||||||
|
block(
|
||||||
|
inset: 5pt,
|
||||||
|
stroke: blue + .3pt,
|
||||||
|
fill: rgb(0, 149, 255, 15%),
|
||||||
|
radius: 4pt,
|
||||||
|
)[#align(left)[#solution]],
|
||||||
|
)
|
||||||
|
#solution
|
||||||
|
]
|
||||||
|
|
||||||
|
#let note(content) = [
|
||||||
|
#align(
|
||||||
|
center,
|
||||||
|
block(
|
||||||
|
inset: 5pt,
|
||||||
|
stroke: luma(20%) + .3pt,
|
||||||
|
fill: luma(95%),
|
||||||
|
radius: 4pt,
|
||||||
|
)[#align(left)[#content]],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
#align(center)[
|
||||||
|
= CS 3843 Computer Organization
|
||||||
|
HW 3\
|
||||||
|
#underline[Price Hiller] *|* #underline[zfp106]
|
||||||
|
]
|
||||||
|
#line(length: 100%, stroke: .25pt)
|
||||||
|
|
||||||
|
+ Assuming $w = 4$, we can assign a numeric value to each possible hexadecimal digit, assuming either an unsigned or a two's-complement interpretation. Fill in the following table according to these interpretations by writing out the nonzero powers of 2 in the summations shown in the equations below:
|
||||||
|
|
||||||
|
$ \B2T_w (accent(x, arrow)) ≐ -x_(w-1)2^(w-1) + sum_(i=0)^(w-2) x_i 2^i $
|
||||||
|
$ \B2U_w (accent(x, arrow)) ≐ sum_(i=0)^(w-1) x_i 2^i $
|
||||||
|
|
||||||
|
#solve[#tablex(
|
||||||
|
columns: 4,
|
||||||
|
column-gutter: 15pt,
|
||||||
|
align: center + horizon,
|
||||||
|
auto-vlines: false,
|
||||||
|
auto-hlines: false,
|
||||||
|
stroke: .5pt,
|
||||||
|
header-rows: 2,
|
||||||
|
|
||||||
|
/* --- header --- */
|
||||||
|
colspanx(2)[$accent(x, arrow)$], colspanx(2)[], colspanx(2)[], colspanx(2)[],
|
||||||
|
hlinex(start: 0, end: 2, stop-pre-gutter: true, stroke: 1pt),
|
||||||
|
[Hexadecimal], [Binary], [$\B2U_4(accent(x, arrow))$], [$\B2T_4(accent(x, arrow))$],
|
||||||
|
hlinex(start: 0, stroke: 1pt),
|
||||||
|
/* -------------- */
|
||||||
|
[0xA], [1010], [$2^3 + 2^1 = 10$], [$-2^3 + 2^1 = -6$],
|
||||||
|
hlinex(start: 0),
|
||||||
|
[0x1], [0001], [$0 ⋅ 2^3 + 0 ⋅ 2^2 + 0 ⋅ 2^1 + 1 ⋅ 2^0 = 1$], [$-0 ⋅2^3 + 0 ⋅ 2^2 + 0 ⋅2^1 + 1 ⋅2^0 = 1$],
|
||||||
|
hlinex(start: 0),
|
||||||
|
[0xB], [1011], [$1 ⋅ 2^3 + 0 ⋅ 2^2 + 1 ⋅ 2^1 + 1 ⋅ 2^0 = 11$], [$-1 ⋅ 2^3 + 0 ⋅ 2^2 + 1 ⋅ 2^1 + 1 ⋅ 2^0 = -5$],
|
||||||
|
hlinex(start: 0),
|
||||||
|
[0x2], [0010], [$0 ⋅ 2^3 + 1 ⋅ 2^2 + 0 ⋅ 2^1 + 0 ⋅ 2^0 = 2$], [$-0 ⋅ 2^3 + 1 ⋅ 2^2 + 0 ⋅ 2^1 + 0 ⋅ 2^0 = 2$],
|
||||||
|
hlinex(start: 0),
|
||||||
|
[0x7], [0111], [$0 ⋅ 2^3 + 1 ⋅ 2^2 + 1 ⋅ 2^1 + 1 ⋅ 2^0 = 7$], [$-0 ⋅ 2^3 + 1 ⋅ 2^2 + 1 ⋅ 2^1 + 1 ⋅ 2^0 = 7$],
|
||||||
|
hlinex(start: 0),
|
||||||
|
[0xC], [1100], [$1 ⋅ 2^3 + 1 ⋅ 2^2 + 0 ⋅ 2^1 + 0 ⋅ 2^0 = 12$], [$-1 ⋅ 2^3 + 1 ⋅ 2^2 + 0 ⋅ 2^1 + 0 ⋅ 2^0 = -4$],
|
||||||
|
)]
|
||||||
|
|
||||||
|
#v(1em)
|
||||||
|
+ We have a machine of 16-bits. This 16-bits machine can be used to represent $2^16$ or $65,536$ different values. We have another machine of 32-bits. This 32-bits machine can be used to represent $2^32$ or $4,294,967,296$ different numbers. So, if you wanted to store a value of $100,000$ then which machine should you choose? The 16-bits machine or 32-bits machine? Mention and explain your choice. (It's Ok to use a calculator for this problem)
|
||||||
|
|
||||||
|
#solve[
|
||||||
|
Generally, we would want to choose the 32-bit system to store a value of $100,000$. The 16-bit system has a max value it can store of $65,535$ which is $< 100,000$ meaning we can't store the $100,000$ value directly in a single word. Whereas, the 32-bit system can store a max value of $4,294,967,295$ which is $>= 100,000$, meaning the value will fit within a single word.
|
||||||
|
|
||||||
|
#note[Now _technically_ we can store $100,000$ on the 16-bit system by spreading the value across multiple words and creating a *lot* of procedures to handle it. This is how naive Big Integer/Big Number libraries work in the wild (notice I mentioned _naive_, there are much, _*much*_, better methods of doing this).]
|
||||||
|
|
||||||
|
Again though, ignoring the aforementioned technicality, we'd want to use the 32-bit system to store the value of $100,000$.
|
||||||
|
]
|
||||||
|
|
||||||
|
#v(1em)
|
||||||
|
+ We have an 8-bits machine. But we don't know if the machine follows unsigned representation or the two's complement/signed representation. A hexadecimal value is given as `0xF1`. Find out the unsigned representation of this hexadecimal value in decimal. Find out the two's complement/signed representation of this hexadecimal value in decimal.
|
||||||
|
#solve[
|
||||||
|
+ `0xF1` to binary: $1111 0001$
|
||||||
|
+ Unsigned representation (_ugh_): $1 ⋅ 2^7 + 1 ⋅ 2^6 + 1 ⋅ 2^5 + 1 ⋅ 2^4 + 0 ⋅ 2^3 + 0 ⋅ 2^2 + 0 ⋅ 2^1 + 1 ⋅ 2^0 = 241$
|
||||||
|
+ Signed representation (_*ugh*_): $-1 ⋅ 2^7 + 1 ⋅ 2^6 + 1 ⋅ 2^5 + 1 ⋅ 2^4 + 0 ⋅ 2^3 + 0 ⋅ 2^2 + 0 ⋅ 2^1 + 1 ⋅ 2^0 = -15$
|
||||||
|
#note[
|
||||||
|
- Alternative way of grabbing the signed value via one's complement:
|
||||||
|
+ Start with `0xF1` to decimal: $1111 0001$
|
||||||
|
+ Recognize that the most significant bit is 1, so we'll multiply our conversions at the end by $-1$
|
||||||
|
+ $~1111 0001 = 0000 1110$
|
||||||
|
+ Add $1$ and pray I understood this right: $0000 1110 + 1 = 00001111$
|
||||||
|
+ $0000 1111$ to decimal is $15$
|
||||||
|
+ Now multiply by $-1$ (and still pray I understood this right): $-1 ⋅ 15 = -15$
|
||||||
|
+ Hallelujah? Do let me know if you have time, I am most curious if I did that right.
|
||||||
|
]
|
||||||
|
|
||||||
|
#note[
|
||||||
|
Some `c` code to grab those values (and for my sane validation):
|
||||||
|
```c
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
unsigned int val = 0xF1;
|
||||||
|
printf("Hex Value: 0x%X\n", val);
|
||||||
|
printf("Unsigned Decimal value: %d\n", (unsigned char)val);
|
||||||
|
printf("Signed Decimal Value %d\n", (signed char)val);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
#v(1em)
|
||||||
|
#text(red)[*Instructions:*]
|
||||||
|
+ Show your work
|
||||||
|
+ You should solve all the problems manually. Then you can use calculator to check your answers.
|
||||||
|
+ You can submit a typed version of your HW or handwritten (scan it/take a photo, then convert it to pdf version. But you need to submit a pdf file.)
|
||||||
|
+ This is an individual HW.
|
||||||
|
+ Late submissions are not allowed.
|
||||||
|
+ Please include your Full Name and abc123 in your HW.
|
Loading…
Reference in New Issue
Block a user