multiplication of two 8bit number

5 次查看(过去 30 天)
Hi, i want to compare the two multiplier output and count the no. of error output. The multiplier width is 8 bit.One is exact multiplier other one is approximate (inaccurate) multiplier. I created the function for approximate multiplier,under the name MULTIPLIER_APPROXIMATE, i checked its functionality, it works as designed. Next, i have to count the no. of error outputs out of (2^8 x 2^8) outputs. I wrote the matlab code which is given below, am not pretty sure whether it works fine. Can someone suggest is this written script is correct one? I am new to this MATLAB platform, am tried my level best. Thanks in advance.
a=0;
b=0;
i=0;
j=0;
num_correct=0;
num_wrong=0;
check=0;
for a=1:256
for b=1:256
[c]=MULTIPLIER_APPROIMATE(a,b);
end
end
for i=1:256
a=i;
for j=1:256
b=j;
check=a*b;
if c==check
num_correct = num_correct + 1;
else
num_wrong = num_wrong + 1;
%dis = e-check;
end
end
end

回答(1 个)

Guillaume
Guillaume 2017-6-3
Well, if you'd tested your code with the debugger you probably would have quickly seen that it does not work.
You have a first set of loop that does nothing but repeatedly overwrite c. At the end c will only contain the value of the last iteration. So your second set of loop after that is not going to do what you want.
I don't particularly understand why you decided to go with two sets of loops. Why can't you do your check at the exact same time you calculate c?
  4 个评论
Reetika Banerjee
Reetika Banerjee 2020-12-2
can anyone tell how to precompute all possible multiplication of two 4 bit binary numbers?
Walter Roberson
Walter Roberson 2020-12-2
[a, b] = ndgrid(0:15)
c = a.*b;
A = randi([0,15]);
B = randi([0,15]);
c(A+1,B+1); %lookup answer

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by