I’ve been meaning for a long time to start learning about some of the fundamentals of Computer Science and have recently got very interested in Computing history. Whether it is the story of J. Presper Eckert and John Mauchly and their work on ENIAC or Alan Turing and his life, I am really interested in where all of this amazing technology that we mostly take for granted started. I want to learn about the people and the technology.
To start with I wanted to learn about digital circuits and how they work. I started with a simple idea, creating a binary calculator using logic gates.
The Half Adder
The logic for a half adder goes like this:
This logic led to me writing the same thing in Python. Python has bitwise Exclusive OR capabilities but I am implementing my half-adder in boolean logic, using only True or False. Here is the code:
def halfadder(a,b): if a != b: s = True c = False return s, c elif a == True and b == True: s = False c = True return s, c else: s = False c = False return s, c
The truth table for this was:
This works, and the inputs for the truth table looks like this in Python:
print(halfadder(False, False)) print(halfadder(True, False)) print(halfadder(False, True)) print(halfadder(True, True))
The outputs produced are correct:
(False, False) (True, False) (True, False) (False, True)
So far so good, next post a Full Adder.