Error observed in using bitsll and bitsra
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Richard McCormack
le 26 Sep 2022
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
Réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!