# Thread: modulo 2 division question help

1. ## modulo 2 division question help

Would anyone know how to write a program that does binary division (modulo 2) for example, take the number 10110010 which is a binary number, and divides it by 1011 which is also a binary number, then see the remainder.

this is what i have so far, it works fine for normail integer division e.g 23 / 7

but it wont work for binary modulo 2 division

Code:
```int posndiv(int divdend, int divisor)
{
int quotient;
int bit_position =1;

if (dividend <=0) {
quotient = -1; /* error cond.: return -1 */
} else if(divisor <= 0) {
quotient = -1; /* error cond.: return -1*/
} else {
quotient = 0;

while ((dividend > divisor) && !(divisor & 0x80000000)){
divisor = divisor << 1;
bit_position = bit_position << 1;
}

while (bit_position > 0) {
if (dividend >= divisor) {
dividend = dividend - divisor;
quotient = quotient + bit_posiition;
}
divisor = divisor >> 1;
bit_position = bit_position >> 1;
}
}
return quotient; // quotient = dividend/divisor
}```

2. ## Re: modulo 2 division question help

Kudo's for using code tags on your first post!! Unfortunately to get the most out of code tags, you must format your code so it's readable. Try indenting your blocks with spaces.

3. >Would anyone know how to write a program that does binary division
this %2 doesn't work?!

4. basically what i want my program to do, is binary division

5. Originally posted by shaq8u
basically what i want my program to do, is binary division
What exactly is binary division? Give me an example of your expected input and output.

Quzah.

6. what it does is: given two binary numbers in ASCII form from std input, it returns the remainder after mod 2 division (xor).
this will then be used to implement crc error detecting method which ive already implemented.

7. this is an example of binary division

http://courses.cs.vt.edu/~csonline/...onTextOnly.html

8. >http://courses.cs.vt.edu/~csonline/...onTextOnly.html
404

Have you seen this?

9. its a great help thank you...it would be great if anyones ever written a code like this before, so maybe they could show me.

Ive seen code on the net, but its just way too big, and too hard to understand, im not an expert at C by any means. but thanks for the help guys

10. //divide by two