Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 left shift
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
turboliux




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Dec 28, 2005 4:33 pm   Post subject: (No subject)

bit shifting is faster
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
wtd




PostPosted: Wed Dec 28, 2005 6:18 pm   Post subject: (No 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.
turboliux




PostPosted: Thu Dec 29, 2005 7:30 am   Post subject: (No subject)

ok thnx
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: