CSEN102: Introduction To Computer Science Winter Semester 2019-2020
CSEN102: Introduction To Computer Science Winter Semester 2019-2020
CSEN102: Introduction To Computer Science Winter Semester 2019-2020
Bar Code
Major
Engineering
BI
4) This exam booklet contains 17 pages, including this one. Three extra sheets of scratch paper are attached
and have to be kept attached. Note that if one or more pages are missing, you will lose their points. Thus,
you must check that your exam booklet is complete.
5) Write your solutions in the space provided. If you need more space, write on the back of the sheet containing
the problem or on the four extra sheets and make an arrow indicating that. Scratch sheets will not be graded
unless an arrow on the problem page indicates that the solution extends to the scratch sheets.
6) When you are told that time is up, stop working on the test.
Good Luck!
1. 7458
2. F ACE16
3. 467
c) Give the least number of bits needed to perform the following operation in two’s complement and perform
the operation afterward.
−21 − 15
d) Let A = 11111010 and B = 00001010 be two 8-bit 2’s complement numbers. Compute the subtraction of
A − B in 2’s complement notation and find out the corresponding decimal value.
CSEN102: Introduction to Computer Science, Final Exam, January 18, 2020 Page 3
b) Simplify the Boolean expression to reach a circuit that can be designed with 2 gates. Use the axioms of the
Boolean Algebra. Please mention the applied rules.
x+0=x x∗1=x
x+1=1 x∗0=0
x+x=x x∗x=x
x + x0 = 1 x ∗ x0 = 0
(x0 )0 = x
x+y =y+x xy = yx Commutativity
x + (y + z) = (x + y) + z x(yz) = (xy)z Associativity
x(y + z) = xy + xz x + yz = (x + y)(x + z) Distributivity
(x + y)0 = x0 y 0 (xy)0 = x0 + y 0 DeMorgan’s Law
A B C X5 X4 X3 X2 X1 X0
0 0 0 1 1 1 1 1 0
0 0 1 0 0 0 0 1 0
0 1 0 0 0 0 1 0 1
0 1 1 0 0 1 0 0 0
1 0 0 0 0 1 0 1 1
1 0 1 0 0 1 1 1 0
1 1 0 0 1 0 0 0 1
1 1 1 0 1 0 1 0 0
What is the functionality of the circuit where A, B, C are the 3 input variables and X5 , X4 , X3 , X2 , X1 and X0
are the 5 output variables? Justify your answer.
CSEN102: Introduction to Computer Science, Final Exam, January 18, 2020 Page 5
Decimal Digit 0 1 2 3 4 5 6 7 8 9
9’Complement 9 8 7 6 5 4 3 2 1 0
a) If you want to design a circuit for 9’s complement converter of digits, how many input variables and how
many output variables do you need? Justify your answer.
b) Draw a truth table that corresponds to the above table. Note: You should neglect all rows that do not
correspond to digits.
c) Find the Boolean expressions of the output variables using the sum of product method.
CSEN102: Introduction to Computer Science, Final Exam, January 18, 2020 Page 6
e) Draw the circuit for the 9’s complement converter using and, or and negation gates.
CSEN102: Introduction to Computer Science, Final Exam, January 18, 2020 Page 7
f) In the following, assume that we want to perform the subtraction of two decimal digits A and B:
A−B
We will be using 9’s complement to perform subtraction through addition. The algorithm is as follows:
1. Get the binary representation of A using 4 bits (let us call it ABin )
2. Get the 9’s complement of B (let us call it Bcomp ).
3. Convert the 9’s complement of B to binary using 4 bits (let us call it BcompBin ).
4. Add ABin and BcompBin
5. If the output is greater than 9:
i. Correct the output by adding 6 (0110) to it
6. Now that you have an output, you check if a carry was produced to generate the output
7. If no carry is generated then:
i. The subtraction is negative
ii. To compute the actual value, take the 9’s complement of the result
8. If a carry is generated, then
i. The final result is positive.
ii. To compute the actual value, add the carry (fifth bit/most significant bit) to the rest of the number
Examples:
1. Computing 8 - 3
• 8 in binary is 1000
• The 9’s complement of 3 is 6: 0110
• 1 0 0 0
0 1 1 0
-------
1 1 1 0
• 9’s complement converters of digits as well as 4-bit adders (presented in lectures) in addition to and,
or and not gates.
• a Greater-Comparator-Than-9 components. This takes as an input a 4-bit binary number and returns 1
if the input is greater than 9 and 0 otherwise.
Hint: Since we have branches in the algorithm presented above, we need to handle the if condition. To
handle an if C then A else B statement, you could use the following Boolean expression:
(C ∗ A) + (C 0 ∗ B)
CSEN102: Introduction to Computer Science, Final Exam, January 18, 2020 Page 9
arr = eval(input())
x = eval(input())
n = len(arr)
r1 = -1
r2 = -1
i = 0
while i<n:
if (x != arr[i]) :
i+=1
else:
r2 = i
if (r1 == -1) :
r1 = i
i += 1
if (r1 != -1) :
print( "First Mystery = " , r1,
"Second Mystery = " , r2)
else :
print("Third Mystery")
arr = [1, 2, 2, 2, 2, 3, 4, 7 ,8 ,8 ]
x = 8
b) What is the functionality of the program for any sorted list of integers with duplicates. Please determine the
meaning of the three mysteries.
CSEN102: Introduction to Computer Science, Final Exam, January 18, 2020 Page 10
c) Give the best case and worst case scenarios. Justify your answer in English without calculating the total
number of operations.
d) Give the total number of operations for the execution of the program for the worst case scenario.
if (r1 != -1) :
print( "First Mystery = " , r1,
" Second Mystery = " , r2)
else :
print("Third Mystery")
Answer of Exercise 6:
CSEN102: Introduction to Computer Science, Final Exam, January 18, 2020 Page 13
Exercise 7
A mathematical joke is a form of humor which relies on aspects of mathematics or a stereotype of mathematicians
[Wikipedia].
Today, we will try to understand Binary jokes.
a) There are 10 types of people in this world. Those who understand binary and those who do not. Who are
these 10 types of people?
b) If only DEAD people understand hexadecimal, how many people understand hexadecimal?
Scratch paper
CSEN102: Introduction to Computer Science, Final Exam, January 18, 2020 Page 15
Scratch paper
CSEN102: Introduction to Computer Science, Final Exam, January 18, 2020 Page 16
Scratch paper