What is the difference between a = a * (2^3) and a = a << 3?
2011-07-26 22:14
579 查看
What is the difference between a = a * (2^3) and a = a <<3?
在面试题中,经常会问,如何高效的实现某个数值乘以2的n次方,标准答案一般是向左移位n位。
其实,这个跟编译器有关系的。当编译器看到常数2的n次方后,可能会直接优化成左移位操作。大家可以自己调试跟踪一下汇编代码。
在面试题中,经常会问,如何高效的实现某个数值乘以2的n次方,标准答案一般是向左移位n位。
其实,这个跟编译器有关系的。当编译器看到常数2的n次方后,可能会直接优化成左移位操作。大家可以自己调试跟踪一下汇编代码。
相关文章推荐
- What is the difference between angle bracket < > and double quotes " " while including header files
- Java-What is the difference between <? super E> and <? extends E>?
- CareerCup What is the difference between a computers heap and it's stack?
- What is the difference between '/n' and '/r/n'? /n /r/n的区别是什么
- What is the difference between << and += while injecting elements to Hash.new([])?
- What is the difference between wc -1 < mydata.dat and wc -1 < mydata.dat ?
- What is the difference between LINQ to SQL and LINQ to Entities?
- What is the difference between a theorem, a lemma, and a corollary?
- What is The Difference Between Risk Appetite, Risk Tolerance and Risk Threshold?
- What is the difference between distributed and parallel processing operating system?
- What is the difference between a Bayesian network and a Naive Bayes classifier?
- What is the difference between primary & secondary storage device?
- what is the difference between the setTimeout and setInterval
- Q: What is the difference between protocol stacks and profiles?蓝牙协议栈和profile的区别
- What is the difference between getWidth/heigth() and getMeasuredWidth/Heigth() in Android SDK?
- What is the difference between SVD and matrix factorization in context of recommendation engine?
- what is the difference between definition and declaration in c
- What is the difference between SET and SELECT when assigning values to variables, in T-SQL?
- What is the difference between addView and addViewInLayout?
- what is the difference between little-endian and big-endian.