Error observed in using bitsll and bitsra
4 次查看(过去 30 天)
显示 更早的评论
When utilizing bitsll and bitsra, an error was noticed.
I have the following code and intend to utilize Embedded.fi [fixed point ] as double implementation show in case -1.
Can someone please show me how to code correctly and help me understand what I'm missing in cases 2 and 3?
It would be nice if I could do cases 2 and 3 in a single function/ single solution.
Thank you very much.
% case -1 : double
k = linspace(-12,12,10);
for i = 1 : length(k)
a = 2 ^ k(i)
end
% case -2: Embdedded fi ,fixed point - right shift
k = fi(linspace(-12,12,10),1,32,27);
a = int8(1);
for i = 1 : length(k)
% fxpOut = bitsra(a,k(i))
disp(bin(bitsra(a,k(i))))
end
% case - 3: Embdedded fi ,fixed point - left shift
k = fi(linspace(-12,12,10),1,32,27);
a = int8(1);
for i = 1 : length(k)
fxpOut = bitsll(a,k(i))
disp(bin(bitsll(a,k(i))))
end
4 个评论
Richard McCormack
2022-9-26
I am happy that you made progress!
I made some adjustments to your code to make it work for code generation.
But maybe there is a reason that you can't use abs. If that is the case, please let me know why you can't use abs.
function scratch
coder.extrinsic('bin');
K = [-12,12];
coder.unroll;
for i = 1:length(K)
if sign(K(i)) < 0 % Bitsliceget to know bitposition and do a bitand for sign
% Negative
b = fi(bitsra(1,abs(K(i))));
disp(bin(b))
else
% Positive
b_i = fi(bitsra(1,abs(K(i))));
disp(bin(b_i))
end
end
end
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!