Shift Left Logical<< [英] Shift Left Logical <<
本文介绍了Shift Left Logical<<的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该如何在C / C ++中做这个?
假设我要向左移动两次 int i ,并将值存储在 f 中。
How exactly do I do this in C/C++? Let's say I want to shift int i twice to the left and store the value in f.
f = i < 2?
f = i << 2 ?
我不需要这个程序或任何东西,我只是感兴趣它的工作原理。感谢。
I don't need this for a program or anything, I'm just interested in how it works. Thanks.
推荐答案
是的。
f = i << 2
移位在一些位的微动操作中很有用。
Shifts are useful in a number of bit twiddling operations.
这是一个将数字乘以4的好方法。但是,这些天,优化编译器往往会为你照顾。
This used to be a great way to multiply a number by four. However, these days, optimizing compilers tend to take care of that for you.
请记住,最左边的两个位被丢弃。
Keep in mind that the two leftmost bits are discarded.
这篇关于Shift Left Logical<<的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文