HDL—Verilog Language—Vectors—Bitwise operators

Build a circuit that has two 3-bit inputs that computes the bitwise-OR of the two vectors, the logical-OR of the two vectors, and the inverse (NOT) of both vectors. Place the inverse of b in the upper half of out_not (i.e., bits [5:3]), and the inverse of a in the lower half.

构建一个具有两个3位输入的电路,该电路计算两个向量的逐位“或”、两个矢量的逻辑“或”以及两个向量之间的(NOT)。将b的倒数放在out_not的上半部分(即bits[5:3]),将a的倒数放置在下半部分。

 整体是不难的,主要注意按位或的运算符是        |        逻辑或的运算符是        ||        

按位或,就例如 : 1010 | 0011 = 1 0 1 1;

逻辑或就是,只要两个数不都是纯0,就输出1

逆其实也有值得注意的地方

Verilog里面有逻辑非“ ! ”和按位非“ ~ ”,两种运算符

逻辑非就是,只要值不是纯0,就输出0。如果是纯0,就输出1。

按位非就是例如:~1100 = 0011

逻辑就是把数值视为一个整体来运算,按位就是一位一位去运算,逻辑的输出只有1或者0,是一位的,按位是输入n位就会产生n位的输出。

module top_module(
    input [2:0] a,
    input [2:0] b,
    output [2:0] out_or_bitwise,
    output out_or_logical,
    output [5:0] out_not
);
assign out_or_bitwise = a | b;
    assign out_or_logical = a || b;
    assign out_not[5:3] = ~ b;
    assign out_not[2:0] = ~ a;
endmodule

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值