Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Non Restoring Division

tahg May 21st, 2020 1,241 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Based on: https://www.geeksforgeeks.org/non-restoring-division-unsigned-integer/
  2.  
  3. #define sign(num, n) ((num >> n) & 1)
  4.  
  5. int Divide(int N, int Q, int M) {
  6.     A = 0;
  7.     szQ = N - 1;
  8.     aM[2] = {-M, M};
  9.     for (; N > 0; N--) {
  10.         sA = sign(A, 31);
  11.         A += A + sign(Q, szQ) + aM[sA];
  12.         Q = (Q + Q + 1) ^ sign(A, 31);
  13.     }
  14.     if (sign(A, 31)) A += M;
  15.     //Q = quotient, A = remainder
  16.     return Q;
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top