title: Performing bit division without arithmetic operators
body: <p>I am trying to complete an assignment that requires me to write three functions for binary arithmetic. badd() was provided for me, so I used it to help write the bsub() and bmult() functions. I am having trouble understanding how I should perform the bdiv() function, however. I know I need to iterate through the bits using a right shift and my bsubb() function, but I don't know how to implement it. Below are the functions that I have written so far. Let me know if you notice any mistakes that I made in writing them(meaning bsub() and bmult()). Thanks. </p>
  
  <pre><code>/** This function adds the two arguments using bitwise operators. Your      
  * implementation should not use arithmetic operators except for loop
  * control. Integers are 32 bits long.  This function prints a message
  * saying "Overflow occurred\n" if a two's complement overflow occurs
  * during the addition process. The sum is returned as the value of
  * the function.
  */
  int badd(int x,int y){
  
  int i;
  
  char sum;
  char car_in=0;
  char car_out;
  char a,b;
  
  unsigned int mask=0x00000001;
  int result=0;
  
  for(i=0;i&lt;32;i++){
  
    a=(x&amp;mask)!=0;
    b=(y&amp;mask)!=0;
    car_out=car_in &amp; (a|b) |a&amp;b;
    sum=a^b^car_in;
  
    if(sum) {
       result|=mask;
    }
  
    if(i!=31) {
       car_in=car_out;
    } else {
       if(car_in!=car_out) {
   printf("Overflow occurred\n");
       }
    }
  
    mask&lt;&lt;=1;
  }
  
   return result;
   }
  
  // subracts two integers by finding the compliemnt
  // of "y", adding 1, and using the badd() function
  // to add "-y" and "x"
  int bsub(int x, int y){
  
  return badd(x, badd(~y, 1));
  }
  
  
  //add x to total for however many y
  int bmult(int x,int y){
  
  int total;
  int i;
  for(i=0; i &lt; = y; i++)
  {
   total = badd(total,x)
  }
   return total;
  }
  
  // comment me
  unsigned int bdiv(unsigned int dividend, unsigned int divisor){
  
  // write me
  return 0;
  }
  </code></pre>