left+right /2
In this article, we’ll take a look at using the left shift and right shift operators in C/C++.
在本文中,我们将研究在C / C ++中使用左移和右移运算符。
These two operators are very useful if you want to do some bit-manipulation operations.
如果要执行一些位操作,这两个运算符非常有用。
Let’s look at them in more detail, using some examples.
让我们使用一些示例更详细地了解它们。
使用左移运算符(<<) (Using the Left Shift Operator (<<))
The Left Shift (<<
) operator is called as the arithmetic left shift operator.
左移位( <<
)运算符称为算术左移位运算符。
This works for both signed as well as unsigned numbers.
这适用于有符号和无符号数字。
Due to this, we can apply this to types like int
, long
, char
, etc.
因此,我们可以将其应用于int
, long
, char
等类型。
This operator left shifts the bits of the number accordingly, by the amount we specify.