Binary Adding Machine

Binary Adding Machine


Charles Petzold's "Code: The Hidden Language of Computer Hardware and Software" has been a favourite of mine. It's available here. This book is highly recommended especially for those new to computer science. Charles does a great job of explaining complex subjects in a comprehensible and beginner-friendly way. You can also find a second edition here.



In chapter 12, Charles describes how to build a simple binary addition machine that can add two 8-bit binary numbers. I decided to develop an implementation of this machine in Minecraft and also in JavaScript. You can download the complete JavaScript repository here.
Premiumcontent.io



In this post, we will walk through the entire process step-by-step. I will demonstrate how I was capable of following the directions in chapter twelve to create this machine using JavaScript and Minecraft. I recommend reading chapter 12 of this book if you want a more detailed explanation of any of these subjects.



Introduction



First, we must be able to add two binary numbers with a 1-bit format to create two binary 8-bit numbers. The sum of these two 1-bit numbers will be an integer of two bits. We'll refer to the first part of this 2-bit number the "sum" bit and the second the "carry" bit. If you were to sing an anthem about it, you might say:



0 plus 0 equals 0.



0 plus 1 equals 1.



1 plus 0 equals 1.



Carry the 1.



The table below further illustrates the sum of our two 1-bit numbers.



Logic Gates



To do all of this, we need to build some logic gates. We'll begin with the AND gate, since we can use it to calculate the carry part. Here is the AND gate I have built in Minecraft (with a little assistance from Mumbo Jumbo).