data/full_repos/permissive/119758565/BCD.v
data/verilator_xmls/e00dd221-42b7-4f04-88ce-b650caa002da.xml
module BCD(
    input [15:0] binary,
	 output reg [3:0] TenThousands,
    output reg [3:0] Thousands,
    output reg [3:0] Hundreds,
    output reg [3:0] Tens,
    output reg [3:0] Ones
    );
	 
	 integer i;
	 reg [15:0] parcedBinary;
	 always @(binary)
	 begin

	     if (binary[15] == 1)
		  begin
		      parcedBinary = ~binary;
				parcedBinary = parcedBinary + 1;
		  end else
		  begin
		      parcedBinary = binary;
	     end
	     TenThousands = 4'b0;
	     Thousands = 4'b0;
	     Hundreds = 4'b0;
	     Tens = 4'b0;
	     Ones = 4'b0;
		  for (i=15; i>=0; i=i-1)
		  begin
		      if(TenThousands >= 5)
				  TenThousands = TenThousands + 3;
		      if(Thousands >= 5)
				  Thousands = Thousands + 3;
		      if(Hundreds >= 5)
				  Hundreds = Hundreds + 3;				  
		      if(Tens >= 5)
				  Tens = Tens + 3;
				if(Ones >= 5)
				  Ones = Ones + 3;
				  
				TenThousands = TenThousands << 1;  
				TenThousands[0] = Thousands[3];
				Thousands = Thousands << 1;  
				Thousands[0] = Hundreds[3];  
				Hundreds = Hundreds << 1;  
				Hundreds[0] = Tens[3];
				Tens = Tens << 1;  
				Tens[0] = Ones[3];  
				Ones = Ones << 1;
				Ones[0] = parcedBinary[i];
		  end
	 end


endmodule
module BCD(
    input [15:0] binary,
	 output reg [3:0] TenThousands,
    output reg [3:0] Thousands,
    output reg [3:0] Hundreds,
    output reg [3:0] Tens,
    output reg [3:0] Ones
    );

	 
	 integer i;
	 reg [15:0] parcedBinary;
	 always @(binary)
	 begin

	     if (binary[15] == 1)
		  begin
		      parcedBinary = ~binary;
				parcedBinary = parcedBinary + 1;
		  end else
		  begin
		      parcedBinary = binary;
	     end
	     TenThousands = 4'b0;
	     Thousands = 4'b0;
	     Hundreds = 4'b0;
	     Tens = 4'b0;
	     Ones = 4'b0;
		  for (i=15; i>=0; i=i-1)
		  begin
		      if(TenThousands >= 5)
				  TenThousands = TenThousands + 3;
		      if(Thousands >= 5)
				  Thousands = Thousands + 3;
		      if(Hundreds >= 5)
				  Hundreds = Hundreds + 3;				  
		      if(Tens >= 5)
				  Tens = Tens + 3;
				if(Ones >= 5)
				  Ones = Ones + 3;
				  
				TenThousands = TenThousands << 1;  
				TenThousands[0] = Thousands[3];
				Thousands = Thousands << 1;  
				Thousands[0] = Hundreds[3];  
				Hundreds = Hundreds << 1;  
				Hundreds[0] = Tens[3];
				Tens = Tens << 1;  
				Tens[0] = Ones[3];  
				Ones = Ones << 1;
				Ones[0] = parcedBinary[i];
		  end
	 end


endmodule