Computer Science Canada

left shift

Author:  turboliux [ Wed Dec 28, 2005 3:58 pm ]
Post subject:  left shift

can someone tell me what is the advantage of using << (left shift) by 1 rather than multyplying by 2? Maybe it had something to do with interpreter?
For example:
code:
int n  = 1;
int m = 1;

n = n<<1;  //n becomes 2
m = m*2;  //m becomes 2

thnx

Author:  Tony [ Wed Dec 28, 2005 4:33 pm ]
Post subject: 

bit shifting is faster

Author:  wtd [ Wed Dec 28, 2005 6:18 pm ]
Post subject: 

It can theoretically be faster. The problem with this is that your compiler may already perform this optimization automatically.

Your best bet is always to say what you mean.

Author:  turboliux [ Thu Dec 29, 2005 7:30 am ]
Post subject: 

ok thnx


: