Binary Adding Machine


Charles Petzold''s "Code: The Secret Language of Computer Hardware and Software" has been a favourite of mine. You can get it here. This book is highly recommended especially for those who are new to computer science. Charles does an excellent job of explaining complex subjects in a simple and easy-to-understand way. I''d like to add that a second edition of this book has recently been released and is available here.



Charles shows how to create a binary adding machine that adds two binary numbers of 8 bits in size. I decided to make an implementation of this machine in Minecraft and also in JavaScript. You can download the complete JavaScript repository here.



In this post we will go through the entire process step-by-step. I will explain how I was successful in following the steps in chapter twelve to create this machine in both JavaScript and Minecraft. I suggest that you read chapter twelve of this book if you need a more thorough explanation of any of these topics.



Introduction



First, we must be able add two 1-bit binary number to add two binary numbers of 8 bits. The sum of these two 1-bit numbers is a two-bit number. The first bit of this 2-bit number will be called the "sum" bit and the second will be"carry" bit. If you wanted to sing a song about it, you could say:



0 plus 0 equals 0.



0 plus 1 equals 1.



1 plus 0 equals 1.



1 plus 1 equals 0, so carry the 1.



The table below explains the sums of our two 1-bit number.



Logic Gates



To do all of this, we''ll need create logic gates. Because we can use it for the calculation of the carry bit, we''ll begin with an AND gate. Here is the AND gate I have built in Minecraft (with some assistance from Mumbo Jumbo).

just another mini blog