Divide Without Operators

Newbie Member
30Aug2006,11:09   #1
arpan's Avatar
I am a 1st year Electronics & Comm Engineering Student
i've been programming in c for 2 years....

I have been told by my senior to

write a c code for Dividing two integers

but

without using any operators ie (+,-,*,/)

get the Quotient and Remainder

One can use math.h .

I cannot figure out this
plz help me
Go4Expert Founder
30Aug2006,11:30   #2
shabbir's Avatar
Use the left shift << or Right shift >> operators to achieve the operation.

Shift left is equivalent to a multiplication by 2.
Similarly a shift right is equal to division by 2
Newbie Member
30Aug2006,11:49   #3
arpan's Avatar
Can you give a small code for using left shift << or Right shift >> operators for dividing with any integer
Go4Expert Member
1Sep2006,11:57   #4
kingo's Avatar
suppose if i give my declarations like
it a=34,b=2,c;

c=a<<b;


wht wil be the value of c?????
Go4Expert Founder
1Sep2006,14:10   #5
shabbir's Avatar
Binary of 34 is 100010
You are asking it for 2 left shift
So the final no would become
10001000 which is 136.

So C will have 136.
Go4Expert Member
1Sep2006,14:41   #6
kingo's Avatar
Actually i got the logic in a crude manner if b=1 it is 34*2
b=2 it is 34*4
Go4Expert Founder
1Sep2006,15:33   #7
shabbir's Avatar
Yes thats true because when you shift bit by one place actually its equivalent to multiplication by 2.