verilog HDL语言编写统计16位二进制数中1的个数。

[复制链接]
查看11 | 回复1 | 2018-3-22 14:33:17 | 显示全部楼层 |阅读模式
module Countnumber(a,result);input [15:0]a;output [4:0]result;reg [4:0]cnt;reg [4:0]width;always@(a)begincnt<=4'd0000;for(width=0;width<16;width=width+1)
//循环判断对应位是1则cnt=cnt+1;if(a[width])cnt<=cnt+1'b1;endassign result=cnt;
//输出result为1的个数;endmodule...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行