什么是'&LT;&LT;'用C是什么意思? [英] What does '<<' mean in C?
问题描述
这是什么意思?
#define WS_RECURSIVE (1 << 0)
据我所知,这将定义 WS_Recursive(1 LT;℃下)
但到底是什么&LT;&LT;
是什么意思?
I understand that it will define WS_Recursive (1 << 0)
but what does <<
mean?
谢谢!
推荐答案
&LT;&LT;
是的left移位运算符。它正在改变数 1
向左 0
位,这相当于数 1
。
<<
is the left shift operator. It is shifting the number 1
to the left 0
bits, which is equivalent to the number 1
.
它通常用于创建的标志的,数字可连同组合|
(位或)和各种操作可以被应用到它们,例如测试一个标志是否被置位,设置一个标志,除去一个标志,等等。
It is commonly used to create flags, numbers that can be combined together with |
(bit or) and various operations can be applied to them, such as testing whether a flag is set, setting a flag, removing a flag, etc.
的原因,他们可以在一起而不彼此干扰组合是,每一个是二的一个的功率,这是用于使用 1所述的原因;&下; X
,因为产生的两个大国:
The reason that they can be combined together without interfering with each other is that each one is a power of two, and that is the reason for using 1 << x
, because that yields powers of two:
1所述;&下; 0 == 2 0 == 1 ==二进制 0001
结果
1 LT;&LT; 1 == 2 1 == 2 ==二进制 0010
结果
1 LT;&LT; 2 == 2 2 == == 4二进制 0100
结果
1 LT;&LT; 3 == 2 3 == == 8二进制 1000
结果
等等
1 << 0 == 20 == 1 == binary 0001
1 << 1 == 21 == 2 == binary 0010
1 << 2 == 22 == 4 == binary 0100
1 << 3 == 23 == 8 == binary 1000
etc
您可以阅读有关此位标志:<一href=\"http://www.$c$cproject.com/KB/tips/Binary_Guide.aspx\">http://www.$c$cproject.com/KB/tips/Binary_Guide.aspx
You can read about bit flags here: http://www.codeproject.com/KB/tips/Binary_Guide.aspx
这篇关于什么是'&LT;&LT;'用C是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!