HDLbits 刷题 --Gatesv100

文章讲述了如何通过逻辑运算(与、或、异或)处理一个100位的输入向量,分别计算出每个比特与其邻居的特定关系:out_both、out_any和out_different。
摘要由CSDN通过智能技术生成

See also the shorter version: Gates and vectors.

You are given a 100-bit input vector in[99:0]. We want to know some relationships between each bit and its neighbour:

  • out_both: Each bit of this output vector should indicate whether both the corresponding input bit and its neighbour to the left are '1'. For example, out_both[98] should indicate if in[98] and in[99] are both 1. Since in[99] has no neighbour to the left, the answer is obvious so we don't need to know out_both[99].
  • out_any: Each bit of this output vector should indicate whether any of the corresponding input bit and its neighbour to the right are '1'. For example, out_any[2] should indicate if either in[2] or in[1] are 1. Since in[0] has no neighbour to the right, the answer is obvious so we don't need to know out_any[0].
  • out_different: Each bit of this output vector should indicate whether the corresponding input bit is different from its neighbour to the left. For example, out_different[98] should indicate if in[98] is different from in[99]. For this part, treat the vector as wrapping around, so in[99]'s neighbour to the left is in[0].

译:

        参见更短的版本: Gates and vectors.

你在[99:0]中得到一个100位的输入向量。我们想知道每个比特和它的邻居之间的关系:

out_both:这个输出向量的每一位都应该表示相应的输入位和它左边的邻居位是否都是“1”。例如,out_both[98]应该指示[98]和[99]是否都是1。因为in[99]在左边没有邻居,所以答案是显而易见的,所以我们不需要知道out_both[99]。

out_any:该输出向量的每一位应该表示是否有任何相应的输入位及其右边的邻居为“1”。例如,out_any[2]应该指示[2]或[1]中是否有一个为1。因为in[0]右边没有邻居,所以答案是显而易见的,所以我们不需要知道out_any[0]。

out_different:该输出向量的每一位都应该表示相应的输入位是否与左边的相邻位不同。例如,out_different[98]应该指示[98]与[99]是否不同。对于这一部分,将向量视为绕行,因此[99]左边的邻居在[0]中。

个人解法:

module top_module( 
    input [99:0] in,
    output [98:0] out_both,
    output [99:1] out_any,
    output [99:0] out_different );
    assign out_both = in[99:1] & in[98:0];
    assign out_any = in[99:1] | in[98:0];
    assign out_different = in ^ ({in[0],in[99:1]});
endmodule

官方解法一致;其实就是前面那个题把长度增加了

运行结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刚及格的陆拾伍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值