【问题标题】:What does using a shift operator(<<) before a variable implies in C? [duplicate]在 C 中变量之前使用移位运算符(<<)意味着什么? [复制]
【发布时间】:2023-03-26 15:05:01
【问题描述】:

我读了一段代码,将一个数字转换成它的二进制等价物,其中使用了以下语句:

1<<j

这样的说法有什么用?

【问题讨论】:

  • 它是左移运算符。它左移(正如你的标题已经说明的那样)。

标签: c operators


【解决方案1】:

1&lt;&lt;j 这意味着将 1 向左移动 j 次。因此,如果j 为 5,则转换结果将是 2^j,如下所示:

 00000001 ====> binary representation of 1
 00100000 ====> binary representation of 32.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-08
    • 2020-06-29
    • 2013-06-05
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多