> For the complete documentation index, see [llms.txt](https://gittest2121.gitbook.io/nand2tetris/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gittest2121.gitbook.io/nand2tetris/combinational-chips/half-adder-chip.md).

# Half Adder Chip

Abstraction and Implementation of Half Adder Chip in Hardware Design Language and Java™.

### Adder Chip

The chip used to add two n-bit numbers is known as Adder, also known as n-bit Adder.

### Half Adder Chip

Half Adder chip is used to add 2-bits.

```nand2tetris-hdl
Chip name: HalfAdder
Inputs: a, b
Outputs: sum, carry
Function: sum = LSB of a + b
          carry = MSB of a + b
```

![Abstraction of Half Adder Chip - Representation and Truth Table](https://1086764272-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61xaDLg3WD0A24S5G3rN%2Fuploads%2FFPd3Uygl7ipv17lwb6Rf%2Fimg.png?alt=media\&token=53481962-a25e-4557-a2f4-25f1b728937e)

### Implementation of Half Adder Chip in HDL

The function in the above abstraction can help in the implementation of Half Adder Chip.

{% hint style="info" %}
sum = a XOR b

carry = a AND b
{% endhint %}

```nand2tetris-hdl
CHIP HalfAdder {
    IN a, b;    // 1-bit inputs
    OUT sum,    // Right bit of a + b 
        carry;  // Left bit of a + b

    PARTS:
    Xor(a=a, b=b, out=sum);
    And(a=a, b=b, out=carry);
}
```

### Implementation of Half Adder Chip in Java™

*Similar to the Implementation in HDL*

```java
package CombChips;

class HalfAdder_Gate extends Xor_Gate {

    protected static int[] HalfAdder(int a, int b) {
        int[] out = new int[2];

        // sum
        out[0] = Xor(a, b);

        // carry
        out[1] = And_Gate.And(a, b);

        return out;
    }
}
```
