🌱Aadam's Garden

Search

Search IconIcon to open search

Half Adder

Last updated Jun 23, 2022

# Half Adder

  • A circuit that adds two bits and outputs a carry and a bit of the sum is called Half Adder.
  • Sum is the XOR of $A$ and $B$, and the carry is the AND of $A$ and $B$, i.e. $$S = A \oplus B, \quad C = AB.$$
    📝 wongIntroductionClassicalQuantum_Half_adder_circuit.excalidraw.svg
  • Code in Verilog:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
module halfadd(C,S,A,B); 
	input A, B; 
	output C, S; 
	
	xor xor1(S,A,B); 
	and and1(C,A,B); 
endmodule 

module main; 
	reg A,B; 
	wire C,S; 
	
	halfadd half1(C,S,A,B); 
	
	initial begin 
		A=0; 
		B=1; 
		#5; // Wait 5 time units. 
		$display("Carry = ",C); 
		$display("Sum = ",S); 
	end 
endmodule

# Sources

# Uses