Binary Adding Machine

Binary Adding Machine


Charles Petzold's "Code: The Secret Language of Computer Hardware and Software" has been a favorite of mine. You can get it here. I highly recommend this book, especially if you're new at computer science. Charles does an excellent job of explaining complex concepts in a digestible and beginner-friendly way. I'd like to add that a new edition of this book was released recently and is available here.



Charles shows how to create an adder machine that adds two binary numbers of 8-bit size. I decided to develop an implementation of this machine in Minecraft as well as in JavaScript. You can download the complete JavaScript repository here.



In this post we will walk through the entire process step-by-step. I will show how I was capable of following the directions in chapter twelve to create this machine in both JavaScript and Minecraft. If you'd like a more thorough explanation of any of the topics listed below, I encourage you to go through chapter 12 of the book mentioned above.



Introduction



First, we need to be able add two binary numbers of 1 bit to create two binary numbers of 8 bits. The sum of these two 1-bit numbers is a two-bit number. We'll refer to the first part of this 2-bit number the "sum" part, and the second the "carry" part.  Sometimes You can sing a song about it:



0 plus 0 equals 0.



0 plus 1 equals 1.



1 plus 0 equals 1.



1 plus 1 equals 0; carry the 1.



The table below shows the sum of our two 1-bit values.



Logic Gates



We'll need logic gates for this. Since we can use them for the calculation of the carry bit, we'll begin with an AND gate. Here's the AND gate I have created in Minecraft (with a little help from Mumbo Jumbo).