Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

test1-odd.fm CS350 Spring 2020 1/4 Test 1, Thur, 2/20/2020 CS350 Spring 2020 1/4 Test 1, Thur, 2/20/2020 Spring 2020, CS350 Test 1, Thur, 2/20/2020 Name: Make sure you have four pages. Do not...

1 answer below »
test1-odd.fm
CS350 Spring 2020 1/4 Test 1, Thur, 2/20/2020
CS350 Spring 2020 1/4 Test 1, Thur, 2/20/2020
Spring 2020, CS350 Test 1, Thur, 2/20/2020
Name:
Make sure you have four pages. Do not take any page(s) with you. Any missing page(s) will result
in failure in the exam. This exam is closed book close notes. Do not exchange anything during the
exam. You all have the same exam. No questions will be answered during the exam, including
typos. I don’t want to give different answers to different people. If you are in doubt,
iefly state
your assumptions below, including typos if any. Make sure you are sitting at the designated seat.
Make sure you are holding your exam, not someone else’s. You may not go to the restroom.

I have read and understood all of the instructions above. On my honor, I pledge that I have not
violated the provisions of the NJIT Academic Honor Code.
Signature: Date:
1. (6 points) Fill the table with =0, !=0, >0, >=0, <0, <=0, n/a (none of the above). Pick the closest one.
2. (4 points) When the following loop is executed: for (i=0;i<10;i++) d = fun(i); what is the earliest itera-
tion that can start triggering "Segmentation fault (core dumped)" when compiled without stack protec-
tor?
Answer: _______________
Question Answer Question Answe
For float f=40000.0, f*f? For int i=40000, i*i?
For float f=60000.0, f*f? For int i=60000, i*i?
For float f=80000.0, f*f? For int i=80000, i*i?
typedef struct {
float x[3];
int y;
} struct_t;
double fun(int i) {
volatile struct_t s;
s.y = 314;
s.x[i] = XXXXXXXXXX;
return s.y;
}
CS350 Spring 2020 2/4 Test 1, Thur, 2/20/2020
CS350 Spring 2020 2/4 Test 1, Thur, 2/20/2020
3. (10 points) Fill in the table for bit and logical operations:
4. (8 points) Fill in with =, >, >=, <, <=, n/a for the relationship between A and B:
5. (4 points) Fill in with =, !=, >, >=, <, <=, n/a for the relationship between A and B:
6. (11 points) Consider a 6-bit two’s complement representation. Fill in the empty boxes in the following
table. Addition and subtraction should be performed based on the rules for 6-bit, two’s complement
arithmetic. TMin refers to the two’s complement minimum while TMax refers to the two’s comple-
ment maximum.
Question Answer in Hexa Question Answer in Hexa
~0x11 !0x11
~0xFF !0xFF
0x96 ^ 0x96 !!0x11
0x96 & 0x96 0xF0 && 0x0F
0x96 | 0x96 0xF0 || 0x0F
Value A A ??? B Value B
0 0U
-1 0U
XXXXXXXXXX XXXXXXXXXX
2147483647U XXXXXXXXXX
-1 -2
(unsigned)-1 -2
XXXXXXXXXX2147483648U
XXXXXXXXXXint)2147483648U
Value A A ??? B Value B
For unsigned int uix=12, uiy=34, uiz=56; (uix+uiy)+uiz uix+(uiy+uiz)
For int six=12, siy=34, siz=56; (six+siy)+siz six+(siy+siz)
For float fx=1.00e+20, fy=-1.00e+20, fz=3.14; (fx+fy)+fz fx+(fy+fz)
(fx+fz)+fy fx+(fz+fy)
CS350 Spring 2020 3/4 Test 1, Thur, 2/20/2020
CS350 Spring 2020 3/4 Test 1, Thur, 2/20/2020
7. (10 points) Derived from saturating_add of HW2 Problem 6, fill in the C statements to compute neg-
ative overflow flag using only bit operators including &, |, ~,
,
. Do not use any logical operators
such as &&, ||, !. Use the following variables only, given x and y are passed as parameters:
int sum = x + y, int_len_less_1 = (sizeof(int)
3)-1;
int sum_mask, x_mask, y_mask, overflow
sum_mask = ___________________________________; /* to find if sum overflows/underflows *
x_mask = _____________________________________; /* to find if x overflows/underflows *
y_mask = _____________________________________; /* to find if y overflows/underflows *
overflow = ____________________________________________________________;
8. (20 points) For signed and unsigned addition, fill in the following table for w=5:
Number Decimal Representation Binary Representation
n/a -15
n/a 011000
n/a 101000
TMin - 1
TMin
TMax
TMax + 1
Type x y x + y x + t5 y Indicate overflow, underflow, n/a
(a) intege
inary XXXXXXXXXX10010
(b) intege
inary XXXXXXXXXX00111
(c) intege
inary XXXXXXXXXX11111
(d) intege
inary XXXXXXXXXX10000
(e) intege
inary XXXXXXXXXX00111
CS350 Spring 2020 4/4 Test 1, Thur, 2/20/2020
CS350 Spring 2020 4/4 Test 1, Thur, 2/20/2020
9. (12 points) Assume 8-bit floats, where bit 7 (the most signifincant bit) is the sign bit, bits 3-6 are expo-
nents, and the rest (bits 0-2) are the significand. Fill in the table below when converting decimal values
to floats:
XXXXXXXXXXpoints) Consider the following 6-bit floating point representation. For denomarlized numbers,
actual exponent is 1 - bias. For nomarlized numbers, actual exponent is E - bias and the implied-1 rule
applies. Fill in the table below. You do not need to fill in entries marked “---”
Value
in decimal
Value
in binary
Before
ounding with
inary point
Exp in
decimal
After
ounding with
inary point
Adjusted
Exp
Result
in decimal
37
38
127
256
Type Sign Exponent E Fraction M Actual Exponent Value
XXXXXXXXXX ---
Denomarlized
actual exponent
= 1 - bias
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
Nomarlized
actual exponent
= E - bias
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX ---
---
XXXXXXXXXX ---
XXXXXXXXXX ---
XXXXXXXXXX ---

test1-v3.fm
CS350 Spring 2022 1/4 Test 1, Thur, 2/17/2022
CS350 Spring 2022 1/4 Test 1, Thur, 2/17/2022
Spring 2022, CS350 Test 1, Thur, 2/17/2022
Name:
Make sure you have four pages. Do not take any page(s) with you. Any missing page(s) will result
in failure in the exam. This exam is closed book close notes. Do not exchange anything during the
exam. You all have the same exam. No questions will be answered during the exam, including
typos. I don’t want to give different answers to different people. If you are in doubt,
iefly state
your assumptions below, including typos if any. Make sure you are sitting at the designated seat.
Make sure you are holding your exam, not someone else’s. You may not go to the restroom.

I have read and understood all of the instructions above. On my honor, I pledge that I have not
violated the provisions of the NJIT Academic Honor Code.
Signature: Date:
1. (20 points) Consider a 7-bit two’s complement representation. Fill in the empty boxes in the
following table. Addition and subtraction should be performed based on the rules for 7-bit,
two’s complement arithmetic. TMin refers to the two’s complement minimum while TMax
efers to the 7-bit two’s complement maximum.
Number Decimal Representation Binary Representation
n/a XXXXXXXXXX
n/a XXXXXXXXXX
TMax + 1
-TMax
TMax + TMax
TMax
-TMin
TMin+1
TMin + TMin
TMin
TMin - 1
CS350 Spring 2022 2/4 Test 1, Thur, 2/17/2022
CS350 Spring 2022 2/4 Test 1, Thur, 2/17/2022
2. (20 points) We are running programs on a machine with the following characteristics:
• Values of type int are 32 bits. They are represented in two’s complement, and they are right
shifted arithmetically. Values of type unsigned are 32 bits.
• Values of type float are represented using the 32-bit IEEE floating point format, while val-
ues of type double use the 64-bit IEEE floating point format.
We generate a
itrary values x, y, and z, and convert them to other forms as follows:
* Create some a
itrary values *
int x = random();
int y = random();
int z = random();
* Convert to other forms *
unsigned ux = (unsigned) x;
unsigned uy = (unsigned) y;
double dx = (double) x;
double dy = (double) y;
double dz = (double) z;
For each of the following C expressions, you are to indicate whether or not the expression always
yields 1. If so, circle “Y”. If not, circle “N”. You will be graded on each problem as follows:
• If you circle no value, you get 0 points.
• If you circle the right value, you get 2 points.
• If you circle the wrong value, you get -1 points (so don’t just guess wildly).
Expression Always True?
(x-y) Y N
17*y+15*x == ((x+y)
4) + y-x Y N
˜(x+y) == ˜x+˜y+1 Y N
-(y-x) == ux-uy Y N
(x < ux) || (x >= 0) Y N
((x
1)
1) <= x Y N
(double)(float) x == (double) x Y N
dx + dy == (double) (y+x) Y N
dx + dy + dz == dz + dy + dx Y N
dx * dy * dz == dz * dy * dx Y N
CS350 Spring 2022 3/4 Test 1, Thur, 2/17/2022
CS350 Spring 2022 3/4 Test 1, Thur, 2/17/2022
3. (25 points) For signed and unsigned addition, fill in the following table for w=5:
4. (15 points) Consider the following 8-bit floating point representation.
For denomarlized numbers, actual exponent is 1 - bias.
For nomarlized numbers, actual exponent is E - bias and the implied-1 rule applies.
Fill in the table below. For Value and Increment columns, fill in only numerators. Do not
change the denominator 512.

Type x y x + y x + t5 y
Indicate overflow,
underflow, n/a
(a) integer in decimal
inary XXXXXXXXXX00111
(b) integer in decimal
inary XXXXXXXXXX10000
(c) integer in decimal
inary XXXXXXXXXX11111
(d) integer in decimal
inary XXXXXXXXXX00111
(e) integer in decimal
inary XXXXXXXXXX10010
Type Sign Exponent E
Fraction
M
Actual
Exponent Value Increment
Denormalized
actual exponent
= 1 - bias
XXXXXXXXXX /512
XXXXXXXXXX /512
XXXXXXXXXX /512
Normalized
actual exponent
= E - bias
XXXXXXXXXX /512
512
XXXXXXXXXX /512
XXXXXXXXXX /512
XXXXXXXXXX /512
XXXXXXXXXX /512
XXXXXXXXXX /512
XXXXXXXXXX /512
XXXXXXXXXX /512
CS350 Spring 2022 4/4 Test 1, Thur, 2/17/2022
CS350 Spring 2022 4/4 Test 1, Thur, 2/17/2022
5. (22 points) Assume 8-bit floats, where bit 7 (the most signifincant bit) is the sign bit, bits 3-6
are exponents, and the rest (bits 0-2) are the significand. Fill in the table below when convert-
ing decimal values to floats. If you are unable to convert to float, write NaN.
6. (22 points) Consider the following 7-bit floating point representation based on the IEEE float-
ing point format:
• There is a sign bit in the most significant bit.
• The next 3 bits are the exponent. The exponent bias is XXXXXXXXXX = 3.
• The last 3 bits are the fraction.
• The representation encodes numbers of the form: V = (-1)s ×M ×2E, where M is the signif-
icand and E is the biased exponent.
The rules are like those in the IEEE standard (normalized, denormalized, representation of 0,
infinity, and NAN). Fill in the table below. Here are the instructions for each field:
• Binary: The 7 bit binary representation.
• M: The value of the significand. This should be a number of the form x or x/y , where x is
an integer, and y is an integral power of 2. Examples include 0, 3/4 .
• E: The integer value of the exponent.
• Value:The numeric value represented.
Note: you need not fill in entries marked with “---”.
Value
in decimal
Value
in binary
Fraction in
inary before
ounding
Exp in
decimal
Fraction in
inary after
ounding
Adjusted
exp in
decimal
Result
in decimal
37
40
126
256 Don’t fill Don’t fill
Description Binary MMantissa
E
Exponent Value
Minus zero -0.0
XXXXXXXXXX
Smallest denormalized (negative)
Largest normalized (positive)
One 1.0
--- 1.5
Positive infinity --- +¥

2021-spring-test1.fm
CS350 Spring 2021 1/4 Test 1, Thur, 2/18/2021
CS350 Spring 2021 1/4 Test 1, Thur, 2/18/2021
Spring 2021, CS350 Test 1, Thur, 2/18/2021
Name:
Make sure you have four pages. Do not take any page(s) with you. Any missing page(s) will result
in failure in the exam. This exam is closed book close notes. Do not exchange anything during the
exam. You all have the same exam. No questions will be answered during the exam, including
typos. I don’t want to give different answers to different people. If you are in doubt,
iefly state
your assumptions below, including typos if any. Make sure you are sitting at the designated seat.
Make sure you are holding your exam, not someone else’s. You may not go to the restroom.

I have read and understood all of the instructions above. On my honor, I pledge that I have not
violated the provisions of the NJIT Academic Honor Code.
Signature:
Answered 4 days After Feb 09, 2023

Solution

Baljit answered on Feb 10 2023
36 Votes
Spring 2020
1.
Before solving the question we should the know the maximum and minimum range of float and int in c

float :- 1.2E-38 to 3.4E+38
int:- -2,147,483,648 to 2,147,483,647 
· For float f=40000.0, f*f?
f*f=1.6E+9 which is in the range of float and so f*f>0
· For float f=60000.0, f*f?
f*f=3.6E+9 which is in the range of float and so f*f>0
· For float f=80000.0, f*f?
f*f=6.4E+9 which is in the range of float and so f*f>0
· For int i=40000, i*i?
f*f=1.6E+9 which is in the range of int and so f*f>0
· For int i=60000, i*i?
f*f=3.6E+9 which is out of the range of int so it will give ga
age value and so n/a
· For int i=80000, i*i?
f*f=6.4E+9 which is out of the range of int so it will give ga
age value and so n/a
2.
Float in c has size 4 bytes so float x[3] has size of 12 bytes. So program will run co
ectly till x[o],x[1],x[2].So core dumped When in function trying to access x[3] in 4th iteration.
3.
Bit wise operatons
· ~0x11
~ operator is called Bitwise NOT and it inverts all the bits. 0x11 is 00010001 in binary. Now we have to just invert the bits from 0 to 1 and 1 to 0.
00010001 → 11101110
11101110 is EE in hexadecimal so our final answer is : 0xEE .
· ~0xFF
we have to perform Bitwise NOT operation. 0xFF is 11111111 in binary.
11111111 → 00000000
00000000 is 00 in hexadecimal so our final answer is : 0x00
· 0x96 ^ 0x96
Now we have to perform Bitwise XOR operation. Bitwise XOR will return 1 if both the bits are different otherwise it will return 0. We are performing this operation on 0x96 and 0x96, as both the numbers are same so Bitwise XOR will return 00000000
00000000 is 00 in hexadecimal so our final answer is : 0x00
· 0x96 & 0x96
Here we have are performing Bitwise AND operation. Bitwise AND will return 1 if both the bits are 1 otherwise it will return 0. We are performing this operation on 0x96 and 0x96, as both the numbers are same so Bitwise AND will return...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here