Bitwise Math Operations: Division

How can you implement bitwise division of two numbers?

Could you give me an example of code in some C-like programming language. Do not propose an answer with constant subtraction of the divisor. I am looking for a faster algorithm.

It should looks like multiply:

public static long Multiply(long mul1, long mul2)
{
    long result = 0;

    while (mul2 != 0)
    {
        if ((mul2 & 1) == 1)
        {
            result = Add(result, mul1);
        }

        mul1 <<= 1;

        mul2 >>= 1;
    }

    return result;
}

Desired output:

public static long Divide(long dividend, long divisor)
{
    long result = 0;
    
    // bitwise division...
    
    return result;
}


from Recent Questions - Stack Overflow https://ift.tt/3mapsmL
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)