Please do the program in \"Scilab\" Please comment the code Implement a function
ID: 3744920 • Letter: P
Question
Please do the program in "Scilab" Please comment the code Implement a function where the final result is a string of characters that shows the PARTIAL REPRESENTATION (E)2 corresponding to the bit length and the exponent (Eo that said function would receive as parameters. An example is shown below: In a 3-bit system for the exponent, the following values are obtained through the PARTIAL REPRESENTATION system. (22 001 | E=-2 010 E-1 011 E-0 1001 E= 1 101 | E-2 Bits 3, (E)10--2 In this case, when entering the following data to the function that we will call Rparcial", the following result should be obtained. ->binario-Rparcial(3,-2) binario 001 In the same way as in the previous example, with the function implemented, find (E)2 corresponding to each subsection. a) Bits 11, (E)10 237 b) Bits 10, E)10-170 c) Bts 13, E)10 1002 d) Bits 14,E)10 7777 e) Bits 8, (E)10 107 f) Bits 12, E)10 785 g) Bits 7,( E)10-33 h) Bits 15, (E)10-10252Explanation / Answer
CODE:
function [binario] = Rparcial(a,b)
m=2^(a-1)-1;//see working examples
x=m+b;//see working examples
binario=dec2bin(x,a);//dec2bin(x,a) converts integer value 'x' to 'a' bit binary number
endfunction
WORKING EXAMPLES:
a) Given: a= 11 & b =237
To find: (E)2
Procedure:
Step 1 : First lets find the value which gives 0 for 11 Bits(in emample 011 gives us 0, 011 when converted to decimal is 3 ). Let that value be m.
m = 2(a-1) - 1 (In this question a = 11)
m = 2(11-1) - 1 (i.e;01111111111 in (E)2)
m = 1023
We have to fnd binary representation of x = m+b i.e: 1023 + 237 = 1260 (this is x)
Now 1260 in (E)2 = 10011101100 (can be written as 100 1110 1100)
(E)2 is binary representaion of 1260.
Our (E)2 should have 11 bits. (because a = 11)
b) Given: a = 10 & b = -170
To find: (E)2
Procedure:
Step 1 : First lets find the value which gives 0 for 10 Bits (in example 011 gives us 0, 011 when converted to decimal is 3 ). Let that value be m.
m = 2(a-1) - 1 (In this question a = 10)
m = 2(10-1) - 1 (i.e;0111111111 in (E)2)
m = 511
We have to fnd binary representation of m+b i.e: 511 - 170 = 341
Now 341 in (E)2 = 0101010101 (can be written as 01 0101 0101)
(E)2 is binary representaion of 341.
Our (E)2 should have 10 bits. (because a = 10)
c) Given: a = 13 & b = 1002
To find: (E)2
Procedure:
Step 1 : First lets find the value which gives 0 for 13 Bits (in example 011 gives us 0, 011 when converted to decimal is 3 ). Let that value be m.
m = 2(a-1) - 1 (In this question a = 13)
m = 2(13-1) - 1 (i.e;0111111111111 in (E)2)
m = 4095
We have to fnd binary representation of m+b i.e: 4095 + 1002 = 5097
Now 5097 in (E)2 = 1001111101001 (can be written as 1 0011 1110 1001)
(E)2 is binary representaion of 5097.
Our (E)2 should have 13 bits. (because a = 13)
d) Given: a = 14 & b = 7777
To find: (E)2
Procedure:
Step 1 : First lets find the value which gives 0 for 14 Bits (in example 011 gives us 0, 011 when converted to decimal is 3 ). Let that value be m.
m = 2(a-1) - 1 (In this question a = 14)
m = 2(14-1) - 1 (i.e;01 1111 1111 1111 in (E)2)
m = 8191
We have to fnd binary representation of m+b i.e: 8191 + 7777 = 15968
Now 15968 in (E)2 = 11111001100000 (can be written as 11 1110 0110 0000)
(E)2 is binary representaion of 15968.
Our (E)2 should have 14 bits. (because a = 14)
e) Given: a = 8 & b = 107
To find: (E)2
Procedure:
Step 1 : First lets find the value which gives 0 for 8 Bits (in example 011 gives us 0, 011 when converted to decimal is 3 ). Let that value be m.
m = 2(a-1) - 1 (In this question a = 8)
m = 2(8-1) - 1 (i.e;0111 1111 in (E)2)
m = 127
We have to fnd binary representation of m+b i.e: 127 + 107 = 234
Now 234 in (E)2 = 11101010 (can be written as 1110 1010)
(E)2 is binary representaion of 234.
Our (E)2 should have 8 bits. (because a = 8)
f) Given: a = 12 & b = 785
To find: (E)2
Procedure:
Step 1 : First lets find the value which gives 0 for 12 Bits (in example 011 gives us 0, 011 when converted to decimal is 3 ). Let that value be m.
m = 2(a-1) - 1 (In this question a = 12)
m = 2(12-1) - 1 (i.e;0111 1111 1111 in (E)2)
m = 2047
We have to fnd binary representation of m+b i.e: 2047 + 785 = 2832
Now 2832 in (E)2 = 101100010000 (can be written as 1011 0001 0000)
(E)2 is binary representaion of 2832.
Our (E)2 should have 12 bits. (because a = 12)
g) Given: a = 7 & b = -33
To find: (E)2
Procedure:
Step 1 : First lets find the value which gives 0 for 7 Bits (in example 011 gives us 0, 011 when converted to decimal is 3 ). Let that value be m.
m = 2(a-1) - 1 (In this question a = 7)
m = 2(12-1) - 1 (i.e;011 1111 in (E)2)
m = 63
We have to fnd binary representation of m+b i.e: 63 - 33 = 30
Now 30 in (E)2 = 0011110 (can be written as 001 1110)
(E)2 is binary representaion of 30.
Our (E)2 should have 7 bits. (because a = 7)
h) Given: a = 15 & b = -10252
To find: (E)2
Procedure:
Step 1 : First lets find the value which gives 0 for 15 Bits (in example 011 gives us 0, 011 when converted to decimal is 3 ). Let that value be m.
m = 2(a-1) - 1 (In this question a = 15)
m = 2(15-1) - 1 (i.e;011 1111 1111 1111 in (E)2)
m = 16383
We have to fnd binary representation of m+b i.e: 16383 - 10252 = 6131
Now 6131 in (E)2 = 001011111110011 (can be written as 001 0111 1111 0011)
(E)2 is binary representaion of 6131.
Our (E)2 should have 15 bits. (because a = 15)