Possible Duplicate:
implement division with bit wise operator
I recently got into more depth by bitwise functions, and started to implement basic arithmetic functions with bitwise operators. So far I have gotten (+, -, *)
. However I'm not really sure how to approach division. I know that I could somehow use multiplication instead, but not sure how to approach this using that method either.
So how would I implement division using only bitwise operators these: (|, &, ~, ^, >>, <<)
in C? For anyone who asks, this is not homework, just personal knowledge.
If you like, you can call the following functions in the code to make it easier (These are prewritten)
int badd(int n1, int n2);
int bsub(int n1, int n2);
int bmult(int n1, int n2);