BCD (Binary Coded Decimal) represents decimal digits (0–9) in pure 4-bit binary.
Excess-3 was obtained by adding 3 (0011) to BCD.
So , to convert back:
BCD=Excess-3−0011
Conversion Rule (Excess-3 → BCD)
Take the Excess-3 input.
Subtract 0011 (3 in binary).
Result = BCD code.
module BCD_Excess03(B,E);
input [3:0] B;
output [3:0] E;
assign E[0] = B[0]^B[1] ;
assign E[1] = B[1]^B[2] ;
assign E[2] = B[2]^B[3];
assign E[3] = B[3];
endmodule
module TB_BCD_Excess03();
reg [3:0] B;
wire [3:0] E;
BCD_Excess03 dux(B,E);
initial
begin
B=4'd0;
#10 B=4'd1;
#10 B=4'd2;
#10 B=4'd3;
#10 B=4'd4;
#10 B=4'd5;
#10 B=4'd6;
#10 B=4'd7;
#10 B=4'd8;
#10 B=4'd9;
#10 B=4'd10;
#10 B=4'd11;
#10 B=4'd12;
#10 B=4'd13;
#10 B=4'd14;
#10 B=4'd15;
#20 $finish();
end
endmodule
module EX3toBCD (
input [3:0] ex3,
output reg [3:0] bcd
);
always @(*) begin
case (ex3)
4'b0011: bcd = 4'b0000;
4'b0100: bcd = 4'b0001;
4'b0101: bcd = 4'b0010;
4'b0110: bcd = 4'b0011;
4'b0111: bcd = 4'b0100;
4'b1000: bcd = 4'b0101;
4'b1001: bcd = 4'b0110;
4'b1010: bcd = 4'b0111;
4'b1011: bcd = 4'b1000;
4'b1100: bcd = 4'b1001;
default: bcd = 4'b0000;
endcase
end
endmodule
module tb_EX3toBCD;
reg [3:0] ex3;
wire [3:0] bcd;
EX3toBCD DUT (
.ex3(ex3),
.bcd(bcd)
);
integer i;
initial begin
for (i = 0; i < 16; i = i + 1) begin
ex3 = i[3:0];
#1;
end
$finish;
end
endmodule
i\p:- J15,L16,M13,R15 o\p:- H17,K15,J13,,N14