# modulo 2 division question help

• 08-17-2003
shaq8u
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 }```
• 08-17-2003
WaltP
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.
• 08-17-2003
saravanan_ts
>Would anyone know how to write a program that does binary division
this %2 doesn't work?!
• 08-17-2003
shaq8u
basically what i want my program to do, is binary division
• 08-18-2003
quzah
Quote:

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.
• 08-18-2003
shaq8u
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.
• 08-18-2003
shaq8u
this is an example of binary division

http://courses.cs.vt.edu/~csonline/...onTextOnly.html
• 08-18-2003
Dave_Sinkula
>http://courses.cs.vt.edu/~csonline/...onTextOnly.html
404

Have you seen this?
• 08-20-2003
shaq8u
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
• 08-20-2003
FillYourBrain
//divide by two