logo

Assignment 1: Computers, data and programming

   

Added on  2023-01-23

8 Pages2156 Words89 Views
 | 
 | 
 | 
Assignment 1: Computers, data and programming
Value: 15%
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]
152b = = b2 x 1 + b1 x 5 + b0 x 2 = b2 + 5b + 2
0x6a = 161 x 6 + 160 x 10 = 96 + 10 = 106
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
Convert 0xBAD to decimal and then decimal value to Base 3
0xBAD = 162 x 11 + 161 x 10 + 160 x 13 = 2816 + 160 + 13 = 2989
Converting this to Base 3
2989 / 3 = 996 R 1
996 / 3 = 332 R 0
332 / 3 = 110 R 2
110 / 3 = 36 R 2
36 / 3 = 12 R 0
12 / 3 = 4 R 0
4 / 3 = 1 R 1
1/ 3 = 0 R 1
Write all remainders in reverse order 0x BAD = 110022013
Assignment 1: Computers, data and programming_1

ii) 3217 into 2-base (binary) representation
3217 / 2 = 1608 R 1
1608 / 2 = 804 R 0
804 / 2 = 402 R 0
402 / 2 = 201 R 0
201 / 2 = 100 R 1
100 / 2 = 50 R 0
50 / 2 = 25 R 0
25 / 2 = 12 R 1
12 / 2 = 6 R 0
6 / 2 = 3 R 0
3 / 2 = 1 R 1
1 / 2 = 0 R 1
3217 = 110010010001b
iii) 1235 into octal representation
1235 / 8 = 154 R 3
154 / 8 = 19 R 2
19 / 8 = 2 R 3
2 / 8 = 0 R 2
1235 = 23238
iv) 21.218 into decimal representation
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
ii) Two's complement
iii) Signed Magnitude
Assignment 1: Computers, data and programming_2

Highest Positive Value Highest Negative Value
One's complement 2(3-1) -1= + 3 - (2(3-1) -1) = -3
Two's complement 2(3-1) -1 = + 3 - (2(3-1)) = -4
Signed Magnitude 2(3-1) -1= + 3 - (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(11
)
Fib(12
)
Fib(13
)
Fib(14
)
Fib(15
)
Fib(16
)
Fib(17
)
Fib(18
)
Fib(19
)
Fib(20
)
Fib(21
)
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 write and run the
program using MARIE simulator. Please include appropriate comments to make your code readable.
[8 marks]
/*******************************************************
/ The Fibonacci numbers program
/*******************************************************
ORG 0
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