multiplication of two 8bit number

4 ビュー (過去 30 日間)
SHOBA MOHAN
SHOBA MOHAN 2017 年 6 月 3 日
コメント済み: Walter Roberson 2020 年 12 月 2 日
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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by