Excess-3 (XS-3) is a non-weighted code used in decimal systems.
It is derived from BCD (Binary-Coded Decimal) by adding 3 (0011₂) to each BCD digit.
Each decimal digit (0–9) is represented by a 4-bit code
Conversion Rule (BCD → Excess-3)
Take the 4-bit BCD input.
Add 0011 (3 in binary).
Result = Excess-3 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 BCDtoEX3 (
input [3:0] bcd,
output reg [3:0] ex3
);
always @(*) begin
case (bcd)
4'b0000: ex3 = 4'b0011;
4'b0001: ex3 = 4'b0100;
4'b0010: ex3 = 4'b0101;
4'b0011: ex3 = 4'b0110;
4'b0100: ex3 = 4'b0111;
4'b0101: ex3 = 4'b1000;
4'b0110: ex3 = 4'b1001;
4'b0111: ex3 = 4'b1010;
4'b1000: ex3 = 4'b1011;
4'b1001: ex3 = 4'b1100;
default: ex3 = 4'b0000;
endcase
end
endmodule
module tb_BCDtoEX3;
reg [3:0] bcd;
wire [3:0] ex3;
BCDtoEX3 DUT (
.bcd(bcd),
.ex3(ex3)
);
integer i;
initial begin
for (i = 0; i < 16; i = i + 1) begin
bcd = i[3:0];
#1;
end
$finish;
end
endmodule
i\p:- J15,L16,M13,R15 o\p:- H17,K15,J13,,N14