Thursday, December 22, 2011

Division without using Division Operator

Write a C program to find division of two numbers without using DIVISION OPERATOR

1 comment:

  1. The standard way to do division is by implementing binary long-division. This involves subtraction, so as long as you don't discount this as not a bit-wise operation, then this is what you should do. (Note that you can of course implement subtraction, very tediously, using bitwise logical operations.)

    In essence, if you're doing Q = N/D:

    1. Align the most-significant ones of N and D.
    2. Compute t = (N - D);.
    3. If (t >= 0), then set the lsb of Q to 1, and set N = t.
    4. Left-shift N by 1.
    5. Left-shift Q by 1.
    6. Go to step 2.

    Loop for as many output bits (including fractional) as you require.

    NOTE:Align the most-significant ones:-
    For instance if N=9 and D=3, then we have N=1001, D=11. So the first thing to do is to left shift D by 2 so that the leading one matches that of N, i.e. you work with D=1100

    ReplyDelete