左移 [英] Bit shifting left
本文介绍了左移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我想将i
左移两次,并将值存储在f
中.
Let's say I want to bit shift i
twice to the left and store the value in f
.
f = i << 2;
那是正确的吗?我该如何在C/C ++中做到这一点?
Is that correct? How exactly do I do this in C/C++?
推荐答案
是.
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.
这篇关于左移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文