A modification in the above code,
int divide(int a, int b)
> {
> int temp = 0;
> int result = 0;
> int mask, i;
>
> printf ("a = %d, b = %d\n", a, b);
>
> temp = 0;
>
> for ( i = 30; i >= 0; i-- ) {
> mask = 1 << i;
>
> temp <<= 1;
>
> temp |= ((a & mask) >> i) & 1;
>
> result <<= 1;
>
> if ( temp >= b ) {
> result |= 1;
> temp -= b;
> }
> }
>
> return result;
> }
>
>
> On Sun, May 22, 2011 at 10:56 PM, Aakash Johari <[email protected]>wrote:
> Try the following code: One can more optimize it.
>
>
>> int divide(int a, int b)
>> {
>> int temp = 0;
>> int result = 0;
>> int mask, i;
>>
>> printf ("a = %d, b = %d\n", a, b);
>>
>> temp = 0;
>>
>> for ( i = 30; i >= 0; i-- ) {
>> mask = 1 << i;
>>
>> temp <<= 1;
>>
>> temp |= ((a & mask) >> i) & 1;
>>
>> result <<= 1;
>>
>> if ( temp >= b ) {
>> result |= 1;
>> temp ^= b;
>> }
>> }
>>
>> return result;
>> }
>>
>>
>
> On Sun, May 22, 2011 at 10:29 PM, Aakash Johari <[email protected]>wrote:
>
>> try for 15 and 3
>>
>>
>> On Sun, May 22, 2011 at 10:22 PM, D.N.Vishwakarma@IITR <[email protected]
>> > wrote:
>>
>>> a divide b
>>>
>>> while(b!=1){
>>> a >>=1;
>>> b >>=1;
>>> }
>>>
>>> printf("%d\n",a);
>>>
>>> On 5/22/11, Wladimir Tavares <[email protected]> wrote:
>>> > a divide b
>>> >
>>> > while(b!=1){
>>> > a <<=1;
>>> > b <<=1;
>>> > }
>>> >
>>> > printf("%d\n",a);
>>> > Wladimir Araujo Tavares
>>> > *Federal University of CearĂ¡
>>> >
>>> > *
>>> >
>>> >
>>> >
>>> >
>>> > On Sun, May 22, 2011 at 1:33 PM, Prakash D IT @ CEG
>>> > <[email protected]>wrote:
>>> >
>>> >> could someone explain the algo with an example?
>>> >>
>>> >>
>>> >> On Sun, May 22, 2011 at 8:21 PM, Puneet Ginoria
>>> >> <[email protected]>wrote:
>>> >>
>>> >>> thnxx all.. i got the soln..
>>> >>> Qdumanshu: i was asking for quotient and remainder when we divide 2
>>> nos.
>>> >>> without actually dividing them...
>>> >>>
>>> >>>
>>> >>>>
>>> >>> --
>>> >>> You received this message because you are subscribed to the Google
>>> Groups
>>> >>> "Algorithm Geeks" group.
>>> >>> To post to this group, send email to [email protected].
>>> >>> To unsubscribe from this group, send email to
>>> >>> [email protected].
>>> >>> For more options, visit this group at
>>> >>> http://groups.google.com/group/algogeeks?hl=en.
>>> >>>
>>> >>
>>> >> --
>>> >> You received this message because you are subscribed to the Google
>>> Groups
>>> >> "Algorithm Geeks" group.
>>> >> To post to this group, send email to [email protected].
>>> >> To unsubscribe from this group, send email to
>>> >> [email protected].
>>> >> For more options, visit this group at
>>> >> http://groups.google.com/group/algogeeks?hl=en.
>>> >>
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "Algorithm Geeks" group.
>>> > To post to this group, send email to [email protected].
>>> > To unsubscribe from this group, send email to
>>> > [email protected].
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/algogeeks?hl=en.
>>> >
>>> >
>>>
>>>
>>> --
>>> **With Regards
>>> Deoki Nandan Vishwakarma
>>> IITR MCA
>>> Mathematics Department*
>>> *
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>
>>
>> --
>> -Aakash Johari
>> (IIIT Allahabad)
>>
>>
>>
>>
>>
>
>
> --
> -Aakash Johari
> (IIIT Allahabad)
>
>
>
>
>
--
-Aakash Johari
(IIIT Allahabad)
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.