I'm currently trying to learn how binary adders work, but I don't understand what a "carry in" is for. What is the purpose of a "carry in"?
It's important to understand there's a difference between a half-adder and a full-adder.
A half-adder is the simplest. It has 2 inputs and 2 outputs. It's basically a XOR.
The primary output is only 1 if one of both inputs is 1, but not if both are 1. That's
Sum. The second output is only 1 if both inputs are 1. That's
That's nice, but only if you're adding two bits. If you need more bits, you'll have to combine some adders together. Here's where full-adders come into play. The Least Significant Adder is a half-adder, and every More Significant Adder will be a full-adder which will take the
Carry of the previous adder.
A B Cin Cout Sum 0 0 0 0 0 1 0 0 0 1 0 1 0 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1
(shamelessly copied from Wikipedia)
Carry in is
0, the behaviour of a full-adder is identical to a half-adder.
Carry in is
1, the behaviour of
Sum is inversed and the behaviour of
Carry out changes into a OR. As long as any of the inputs is 1,
Carry out is 1.
Carry in is required to turn a basic 2-bit adder into a multiple-bit counter. That's the purpose of
Besides what is said by those who replied earlier, Carry can also mean an input coming from the flag register that allows linking one sum on a ALU to the next one. By linking I mean that, if your computer architecture has a ALU with a word size of 8 bits and you need to do a 16 bit sum, the ALU can use the Carry flag, placing it on its carry in as a way to allow the processor to continue the sum from the previous one. This allows two 8 bit sums to become a single two step 16bit sum.
The purpose of the "carry" in is to accept the "carry" out of the previous adder. Carry works just like normal arithmetic.