Half Adder Problem

You are going to make a small class to simulate a half-adder. This is a circuit that adds two bits together. The half part is because it doesn't handle a carry. The class will have a method that takes two arguments. These are the two bits it will add.

We are going to do this using logical functions, rather than arithmetical ones. These are the single & and single | operators. Here are some expressions that will result in the answer. In this, A is one of the inputs and B is the other. The first step is to AND A and B
x1 = !A (not A) & B

x2 = A & !B (not B)

x3 = A & B (This is the carry)

x4 = x1 | x2 (This is the sum)

There will be two other methods, one to retrieve the sum and one to retrieve the carry.

Inputs:

Two bits to add, represented as integers.

Outputs

Print the bits to be added and the sum and carry thar result.

Answer

Here is one solution to this problem. Here is a Java solution to this problem. Here is the main code in Java for this problem.