logo

Assignment 1: Computers, data and programming

   

Added on  2022-12-15

6 Pages1699 Words419 Views
 | 
 | 
 | 
back to top
Assignment 1: Computers, data and programming
Value: 15%
Due Date: 26-Apr-2019
Return Date: 20-May-2019
Submission method options: Alternative submission method
Task
back to top
Total marks: 30
Answer the following Questions
Question 1.
a) Determine the value of base b if (152)b = 0x6A. Please show all steps.
[3 marks]
0x6a = 161 x 6 + 160 x 10 = 96 + 10 = 106
152b = = b2 x 1 + b1 x 5 + b0 x 2 = b2 + 5b + 2
b2 + 5b + 2 = 106
(b + 13) ( b – 8 ) = 0
Base must be +ve number i.e. 8
b) Convert the followings: (Please show all steps; no marks will be awarded if no steps are
shown)
[1.5x4 = 6 marks]
i) 0xBAD into 3-base representation
0xBAD = 162 x 11 + 161 x 10 + 160 x 13 = 2816 + 160 + 13 = 2989
Converting this to Base 3
2989 = 996 * 3 + 1
996 = 332 * 3 + 0
332 = 110 * 3 + 2
110 = 36 * 3 + 2
36 = 12 * 3 + 0
Assignment 1: Computers, data and programming_1

12 = 4 * 3 + 0
4 = 1 * 3 + 1
1 = 0 * 3 + 1
Write remainders in reverse order
0x BAD = 110022013
ii) 3217 into 2-base (binary) representation
3217 = 1608 * 2 + 1
1608 = 804 *2 + 0
804 = 402 * 2 + 0
402 = 201 * 2 + 0
201 = 100 * 2 +1
100 = 50 * 2 + 0
50 = 25 * 2 + 0
25 = 12 * 2 +1
12 = * 2 +0
6 = 3 * 2 + 0
3 = 1 * 2 + 1
1 = 0 * 2 + 1
3217 = 110010010001b
iii) 1235 into octal representation
1235 = 1 * 52 + 2 * 51 + 3 * 50 = 25 + 10+3 = 38
38 = 4 * 8 +6
4 = 0* 8 + 4
1235 = 468
iv) 21.218 into decimal representation
21.21 = 2 * 81 + 1 * 80 + 2 * 8-1 + 1 * 8-2
= 16 + 1 + 0.125 + 0.015625 = 17.140625
Assignment 1: Computers, data and programming_2

c) Given a (very) tiny computer that has a word size of 3 bits, what are the lowest value
(negative number) and the highest value (positive number) that this computer can represent in
each of the following representations?
[3 marks]
i) One's complement
Highest Positive Value = 2(N-1) -1 = 2(3-1) -1= + 3
Highest Negative Value = -(2(N-1) -1) = - (2(3-1) -1) = -3
ii) Two's complement
Highest Positive Value = 2(N-1) -1 = 2(3-1) -1= + 3
Highest Negative Value = -(2(N-1))= - (2(3-1)) = -4
iii) Signed Magnitude
Highest Positive Value = 2(N-1) -1 = 2(3-1) -1= + 3
Highest Negative Value = -(2(N-1) -1) = - (2(3-1) -1) = -3
Question 2.
a) The Fibonacci numbers are the numbers in the following integer sequence, called the
Fibonacci sequence, and are characterised by the fact that every number after the first two is
the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 114, ... etc.
By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each
subsequent number is the sum of the previous two. We define Fib(0)=0, Fib(1)=1, Fib(2)=1,
Fib(3)=2, Fib(4)=3, etc. The first 22 Fibonacci numbers given below:
Fib(0
)
Fib(1
)
Fib(2
)
Fib(3
)
Fib(4
)
Fib(5
)
Fib(6
)
Fib(7
)
Fib(8) Fib(9
)
Fib(10
)
0 1 1 2 3 5 8 13 21 34 55
Fib(1
1)
Fib(1
2)
Fib(1
3)
Fib(1
4)
Fib(1
5)
Fib(1
6)
Fib(1
7)
Fib(1
8)
Fib(1
9)
Fib(2
0)
Fib(2
1)
89 144 233 377 610 987 1597 2584 4181 6765 10946
Write a MARIE program to calculate Fib(n), where the user inputs n. For example, if the user
inputs 7, the program outputs the value 13; if the user inputs 15, the program outputs the
value 610; if the user inputs 20, the program outputs the value 6765 and so on. You need to
Assignment 1: Computers, data and programming_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents