# Using shift operator for faster division and multiplication

Discussion in 'Programming' started by pradeep, Feb 21, 2007.

Joined:
Apr 4, 2005
Messages:
1,645
87
Trophy Points:
0
Occupation:
Programmer
Location:
Kolkata, India
Multiplications

12 * 2 = 12 << 1
12 * 4 = 12 << 2
12 * 8 = 12 << 3
12 * 16 = 12 << 4
12 * 32 = 12 << 5
12 * 64 = 12 << 6
12 * 128 = 12 << 7
12 * 256 = 12 << 8

Divisions

12 / 2 = 12 >> 1
12 / 4 = 12 >> 2
12 / 8 = 12 >> 3
12 / 16 = 12 >> 4
12 / 32 = 12 >> 5
12 / 64 = 12 >> 6
12 / 128 = 12 >> 7
12 / 256 = 12 >> 8

Code:
``` #include<stdio.h>

void main(void)
{
int a;

a = 12 << 1;

printf("%d",a);
}
```

2. ### mayjuneNew Member

Joined:
Jun 14, 2009
Messages:
814
33
Trophy Points:
0
Occupation:
Student
Location:
Pune,Delhi
in machine terms,
for i12 / 256, 12 >> 8 is faster. Is that what you mean?
or just for easier calculations?

3. ### teacherNew Member

Joined:
Mar 27, 2011
Messages:
66
8
Trophy Points:
0
Occupation:
i hate jobs
Location:
india,agra
```// before: binary equivalent 10000000