Incorrect non restoring division for unsigned integers !!

3 views (last 30 days)
Hi there,
For unsigned integer values, I am attempting to construct a non-restoring division algorithm, but it appears that I am having difficulties getting the quotient and remainder right.
Can you give me some advice on how to improve the implementation?
Many thanks
clearvars;clc;
n = 32;
N = 11;
D = 3;
R = zeros(1,1);
Q = 0;
D = bitshift(D, 1);
for i = 1 : (n-1) %.. 0 do -- for example 31..0 for 32 bits
if R >= 0
Q = accumpos(Q,1);
R = 2 * R - D;
else
Q = accumneg(Q,1);
R = 2 * R + D;
end
end
Q = Q - not(Q); % -- Appropriate if −1 digits in Q are represented as zeros as is common.
if R < 0
Q = accumneg(Q,1);
R = R + D; %-- Needed only if the remainder is of interest.
end
Q ,R
Q = -30
R = 0

Answers (0)

Categories

Find more on Elementary Math in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by