mod.js
function mod(A, B) {
  var C = 1, D = 0
  var _B = B
  if (B > A) return A

  //shift B right until it it's just smaller than A.
 while(B < A) {
    B<<=1; C<<=1
  }
  //now, shift B back, while subtracting.
  do {
    B>>=1; C>>=1

    //mark the bits where you could subtract.
    //this becomes the quotent!
    if(B < A) {
      D |= C; A = A - B
    }
    console.log('=', D.toString(2))
  } while(B > _B) 
  console.log(D, D.toString(2))
  return A
}
function mod(A, B) {
  var C = 1, D = 0
  var _B = B
  if (B > A) return A

  //shift B right until it it's just smaller than A.
 while(B < A) {
    B<<=1; C<<=1
  }
  //now, shift B back, while subtracting.
  do {
    B>>=1; C>>=1

    //mark the bits where you could subtract.
    //this becomes the quotent!
    if(B < A) {
      D |= C; A = A - B
    }
    console.log('=', D.toString(2))
  } while(B > _B) 
  console.log(D, D.toString(2))
  return A
}
function mod ( A , B ) { var C = 1 , D = 0 var _B = B if ( B > A ) return A //shift B right until it it's just smaller than A. while ( B < A ) { B <<= 1 ; C <<= 1 } //now, shift B back, while subtracting. do { B >>= 1 ; C >>= 1 //mark the bits where you could subtract. //this becomes the quotent! if ( B < A ) { D |= C ; A = A - B } console . log ( '=' , D . toString ( 2 ) ) } while ( B > _B ) console . log ( D , D . toString ( 2 ) ) return A }
calculate A % B
calculate A % B