operator-keyword - verilog 中的“<<”运算符

标签 operator-keyword verilog

我有一个 verilog 代码,其中有一行如下:

parameter ADDR_WIDTH = 8 ;
parameter RAM_DEPTH = 1 << ADDR_WIDTH;

这里将存储什么 RAM_DEPTH << 是什么?运营商在这里做。

最佳答案

<<是二进制移位,将 1 向左移位 8 位。

4'b0001 << 1 => 4'b0010
>>是向 MSB 添加 0 的二进制右移。>>>是有符号移位,如果左输入有符号,则保持 MSB 的值。
4'sb1011 >>  1 => 0101
4'sb1011 >>> 1 => 1101

表示左操作数有符号的三种方式:
module shift;
  logic        [3:0] test1 = 4'b1000;
  logic signed [3:0] test2 = 4'b1000;

  initial begin
    $display("%b", $signed(test1) >>> 1 ); //Explicitly set as signed
    $display("%b", test2          >>> 1 ); //Declared as signed type
    $display("%b", 4'sb1000       >>> 1 ); //Signed constant
    $finish;
  end
endmodule

关于operator-keyword - verilog 中的“<<”运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17691265/

相关文章:

prolog - 在 Prolog 中重新定义 AND 运算符

verilog - 我如何知道我的代码是否可综合? [Verilog]

测试 Verilog 模块

verilog - 在verilog中包含一个模块

verilog - Verilog 中的子模块

c++ - 无法使用 istream C++ 重载 >> 运算符

c++ - 重载 C++ 运算符 >> 这样我就可以读取一个 vector (vector <int> vector;)

c++ - 插入运算符重载有什么问题? (<< 运算符)

arrays - Verilog:在分层路径中使用数组元素

c++ - C++中的字符串类赋值运算符重载