<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Exploring Binary &#187; Binary logic</title>
	<atom:link href="http://www.exploringbinary.com/category/binary-logic/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.exploringbinary.com</link>
	<description>Binary Numbers, Binary Code, and Binary Logic</description>
	<lastBuildDate>Tue, 31 Jan 2012 16:38:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Binary Properties of a 4-Way Switch Circuit</title>
		<link>http://www.exploringbinary.com/binary-properties-of-a-4-way-switch-circuit/</link>
		<comments>http://www.exploringbinary.com/binary-properties-of-a-4-way-switch-circuit/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 18:21:32 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Binary logic]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=293</guid>
		<description><![CDATA[Recently I had to replace a 4-way switch, an electrical component that lets you turn a light on or off from three or more locations. While installing it, I thought about the binary properties of my three-switch circuit: I saw powers of two, binary logic, and binary gray code. I drew some diagrams, including a [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/binary-properties-of-a-4-way-switch-circuit/">Binary Properties of a 4-Way Switch Circuit</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Recently I had to replace a 4-way switch, an electrical component that lets you turn a light on or off from three or more locations. While installing it, I thought about the binary properties of my three-switch circuit: I saw <a href="http://www.exploringbinary.com/the-powers-of-two/" title="Read Rick Regan's Article &ldquo;The Powers of Two&rdquo;">powers of two</a>, binary logic, and binary <a title="Wikipedia article on Gray Code" href="http://en.wikipedia.org/wiki/Gray_code">gray code</a>. I drew some diagrams, including a state machine. I&#8217;ll share my thoughts and diagrams with you in this article.</p>
<div class="wp-caption aligncenter" style="width: 520px"><img src="http://www.exploringbinary.com/wp-content/uploads/4-way.example.sequence.jpg" alt="Example Switching Sequence of Three Light Switches" width="510" height="78"/><p class="wp-caption-text">Example Switching Sequence of Three Light Switches</p></div>
<p><span id="more-293"></span></p>
<h2>On/Off, 3-Way and 4-Way Switches</h2>
<p>To control a light from one location, all you need is a simple on/off switch. The switch either closes the circuit, in which case the light goes on, or it opens the circuit, in which case the light goes off. Essentially, the switch takes two ends of a wire and connects or disconnects them. In a one-switch circuit, the position of the switch correlates with the state of the light; for example, up will mean on, and down will mean off.</p>
<p>To control a light from two locations, you need two 3-way switches, connected by two &#8220;traveler&#8221; wires. For example, here&#8217;s a two-switch circuit, with both 3-way switches in the down position:</p>
<div class="wp-caption aligncenter" style="width: 255px"><img src="http://www.exploringbinary.com/wp-content/uploads/4-way.3-way.jpg" alt="Example State of a Two-Switch Circuit" width="245" height="114"/><p class="wp-caption-text">Example State of a Two-Switch Circuit</p></div>
<p>Each switch can be up or down, connecting a single wire to one of two other wires. Since there are two switches that can each be in two positions, there are 2<sup>2</sup> = 4 switch states in all.</p>
<p>To control a light from three or more locations, you need one or more 4-way switches sandwiched between two 3-way switches, with a pair of traveler wires connecting each switch. For example, here&#8217;s a three-switch circuit, with both 3-way switches in the down position and the 4-way switch in the up position:</p>
<div class="wp-caption aligncenter" style="width: 354px"><img src="http://www.exploringbinary.com/wp-content/uploads/4-way.4-way.up.jpg" alt="Example State of a Three-Switch Circuit" width="344" height="115"/><p class="wp-caption-text">Example State of a Three-Switch Circuit</p></div>
<p>When the 4-way switch is in the down position, the traveler connections are crossed, inverting the state of the circuit; for example:</p>
<div class="wp-caption aligncenter" style="width: 352px"><img src="http://www.exploringbinary.com/wp-content/uploads/4-way.4-way.down.jpg" alt="Example State of a Three-Switch Circuit" width="342" height="106"/><p class="wp-caption-text">Example State of a Three-Switch Circuit</p></div>
<p>(I&#8217;m assuming arbitrarily that &ldquo;up&rdquo; is the direct connection and &ldquo;down&rdquo; is the crossed connection; I don&#8217;t know what it actually is, but it doesn&#8217;t matter.)</p>
<p>With three switches, there are 2<sup>3</sup> = 8 different switch states. (You can see the pattern &#8212; with n switches, there are 2<sup>n</sup> states.)</p>
<p>In a multiple-switch circuit, the position of an individual switch <em>does not</em> correlate with the state of the light &#8212; turning a switch up or down can turn the light on or off, depending on the position of the other switch(es).</p>
<h2>A Three-Switch Circuit</h2>
<p>Here are all eight states of a three-switch light circuit:</p>
<div class="wp-caption aligncenter" style="width: 355px"><img src="http://www.exploringbinary.com/wp-content/uploads/4-way.internals.jpg" alt="All Eight States of a Three-Switch Circuit" width="345" height="613"/><p class="wp-caption-text">All Eight States of a Three-Switch Circuit</p></div>
<p>Here are the same states, but shown with the position of the light switches (the switches are of course separate, but I&#8217;ve drawn them together):</p>
<div class="wp-caption aligncenter" style="width: 127px"><img src="http://www.exploringbinary.com/wp-content/uploads/4-way.switches.jpg" alt="All Eight States of a Three-Switch Circuit" width="117" height="488"/><p class="wp-caption-text">All Eight States of a Three-Switch Circuit</p></div>
<p>Of the eight states, half close the circuit and turn the light on, and half open the circuit and turn the light off.</p>
<h2>State Machine</h2>
<p>This state machine captures the logic of any switching sequence:</p>
<div class="wp-caption aligncenter" style="width: 402px"><img src="http://www.exploringbinary.com/wp-content/uploads/4-way.states.jpg" alt="State Machine Diagram for a Three-Switch Circuit" width="392" height="412"/><p class="wp-caption-text">State Machine Diagram for a Three-Switch Circuit</p></div>
<p>There are eight states.  Each arrow represents the change of position of one switch &#8212; to up or down. From each state you can go directly to three other states. You can go indirectly to any other state by traversing a path through the diagram. The light toggles from off to on or from on to off with each change of switch position. </p>
<h2>Gray Code</h2>
<p>If each switch is viewed as a bit &#8212; I&#8217;ve labeled up as &lsquo;1&rsquo; and down as &lsquo;0&rsquo;, by convention &#8212; then there are eight binary values: 000, 001, 010, 011, 100, 101, 110, 111. As listed, that is the counting order for the binary integers zero through seven. In this order, multiple bits can change between two adjacent numbers; for example, two bits change from 001 to 010. But in a light circuit, no toggling sequence of the eight states can result in binary counting order, because only one switch can change at a time (I&#8217;m not counting two or three people toggling switches at the same time!).</p>
<p>This is where gray code comes in. A gray code is an ordering of binary numbers such that only one bit changes between adjacent numbers. For example, a three-bit gray code &#8212; known as the <em>binary reflected gray code</em> &#8212; is 000, 001, 011, 010, 110, 111, 101, 100. (You&#8217;ll note that that&#8217;s the order in which I listed the switch states in the diagrams above). There are many possible three-bit gray codes, each represented by a unique traversal of all eight states in the state diagram.</p>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/binary-properties-of-a-4-way-switch-circuit/">Binary Properties of a 4-Way Switch Circuit</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/binary-properties-of-a-4-way-switch-circuit/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ki-Adi-Mundi Has a Binary Brain Too</title>
		<link>http://www.exploringbinary.com/ki-adi-mundi-has-a-binary-brain-too/</link>
		<comments>http://www.exploringbinary.com/ki-adi-mundi-has-a-binary-brain-too/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 13:56:08 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Binary logic]]></category>
		<category><![CDATA[Pop culture]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=218</guid>
		<description><![CDATA[I&#8217;m not the only one with a binary brain. The other day my son showed me a page in a Star Wars&#174; book which described a character named Ki-Adi-Mundi, who up until that point we knew as &#8220;big brain head.&#8221; I read in his bio that he has a binary brain, at which point I [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/ki-adi-mundi-has-a-binary-brain-too/">Ki-Adi-Mundi Has a Binary Brain Too</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not the only one with a binary brain.</p>
<p>The other day my son showed me a page in a Star Wars&reg; book which described a character named Ki-Adi-Mundi, who up until that point we knew as &#8220;big brain head.&#8221; I read in his bio that he has a binary brain, at which point I exclaimed, &#8220;Hey, just like me!&#8221; Well, not quite &#8212; his is binary in a different sense:</p>
<p>From <a href="http://www.starwars.com/explore/encyclopedia/characters/kiadimundi/" title="Read about Ki-Adi-Mundi">starwars.com</a>:</p>
<blockquote><p>&#8220;Ki&#8217;s most distinguishing physical feature was an enlarged conical cranium that contained a <span class="highlight_underline">binary brain</span>.&#8221;</p></blockquote>
<p><span id="more-218"></span>From <a href="http://starwars.wikia.com/wiki/Ki-Adi-Mundi" title="Read about Ki-Adi-Mundi">wikia.com</a>:</p>
<blockquote><p>&#8220;&#8230; his <span class="highlight_underline">binary brain</span> made him extremely logical and insightful &#8230;&#8221;</p></blockquote>
<p>From <a href="http://starwars.wikia.com/wiki/Cerean" title="Read about the Cerean species">wikia.com</a>, about his species, Cerean:</p>
<blockquote><p>&#8220;Their enlarged skulls, extending up to twenty centimeters above their foreheads, housed <span class="highlight_underline">complex binary brains</span> &#8230;&#8221;</p></blockquote>
<blockquote><p>&#8220;They had tall tapering heads, which housed <span class="highlight_underline">large binary brains</span>, enabling them to focus on many things at the same time.&#8221;</p></blockquote>
<blockquote><p>&#8220;The <span class="highlight_underline">binary structure</span> of Cerean thinking helped them to ponder two sides of an issue at once.&#8221;</p></blockquote>
<p>From <a href="http://www.cuswe.org/search.asp?t=&#038;EandD=EyDn&#038;e=&#038;c=&#038;p=&#038;a=&#038;no=10&#038;s=JQ4" title="Read about the Cerean species">another site</a> regarding the Cereans:</p>
<blockquote><p>&#8220;Contained within the skull was a <span class="highlight_underline">binary brain</span>, which gave a Cerean an advanced capacity for thinking and meditation.&#8221;</p></blockquote>
<p>Well, maybe our brains aren&#8217;t that different after all. I wonder if he reads this blog. <img src='http://www.exploringbinary.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/ki-adi-mundi-has-a-binary-brain-too/">Ki-Adi-Mundi Has a Binary Brain Too</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/ki-adi-mundi-has-a-binary-brain-too/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Binary Marble Adding Machine</title>
		<link>http://www.exploringbinary.com/the-binary-marble-adding-machine/</link>
		<comments>http://www.exploringbinary.com/the-binary-marble-adding-machine/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 16:29:40 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Binary logic]]></category>
		<category><![CDATA[Convert to binary]]></category>
		<category><![CDATA[Convert to decimal]]></category>
		<category><![CDATA[Geekware]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=197</guid>
		<description><![CDATA[The Binary Marble Adding Machine is a device that adds binary numbers mechanically. It uses wood instead of silicon, gravity instead of voltage, and marbles instead of current. We don&#8217;t need no stinkin&#8217; CMOS! The machine may be more cool than practical, but it certainly is educational. It illustrates basic principles of binary numbers, binary [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/the-binary-marble-adding-machine/">The Binary Marble Adding Machine</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The <a title="Binary Marble Adding Machine" href="http://woodgears.ca/marbleadd/index.html">Binary Marble Adding Machine</a> is a device that adds binary numbers mechanically. It uses wood instead of silicon, gravity instead of voltage, and marbles instead of current. We don&#8217;t need no stinkin&#8217; CMOS!</p>
<p class="center"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/GcDshWmhF4A&amp;hl=en&amp;fs=1" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/GcDshWmhF4A&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>The machine may be more cool than practical, but it certainly is educational. It illustrates basic principles of binary numbers, binary arithmetic, and binary logic. Let&#8217;s take a closer look. </p>
<p><span id="more-197"></span>(I&#8217;ll be writing this as if you have the machine in front of you, but you won&#8217;t; I think less than ten were made.)</p>
<h2>What the Machine Does</h2>
<p>The marble adding machine adds 6-bit, positive binary integers; that is, numbers, when expressed in decimal form, are between 0 and 63 (of course adding zero is not interesting &#8212; there&#8217;s nothing to do). It takes a binary integer as input, adds it &#8212; using binary arithmetic &#8212; to the binary integer present in its memory, and then presents the resulting binary integer as output.</p>
<p>The machine can store a maximum sum of 63; that is, 2<sup>6</sup> &#8211; 1. If you exceed this, the machine overflows, meaning it stores the sum modulo 64. For example, 57 + 12 = 5, and 63 + 1 = 0.</p>
<h2>Input/Output</h2>
<p>To add two or more binary numbers, simply enter them into the machine one at a time. To enter a number, place marbles in the slots corresponding to the 1-bits; leave the slots corresponding to the 0-bits empty. For example, the number 1101, which is 13, would look like this:</p>
<div class="wp-caption aligncenter" style="width: 397px"><img class="centered" title="1101, or 13, as it would appear in the input or output tray." src="http://www.exploringbinary.com/wp-content/uploads/Marble-Adder-IO-1101.jpg" alt="1101, or 13, as it would appear in the input or output tray." width="387" height="70" /><p class="wp-caption-text">1101, or 13, as it would appear in the input or output tray.</p></div>
<p>The number 1101 is only 4 bits, but it is equivalent to 001101; leading zeros are implied. To avoid confusion, load marbles from right to left. You&#8217;ll be sure to get them in the correct slots that way.</p>
<p>Output is in the same form as the input: empty slots represent zeros, and slots with marbles represent ones.</p>
<h3>Working in Decimal</h3>
<p>Although the machine adds binary numbers, it&#8217;s more likely you&#8217;ll want to add decimal numbers. This requires conversion between decimal and binary. Before you enter a number, you must convert it to binary. To read the result, you must convert it to decimal.</p>
<p>Practically speaking, you&#8217;ll find that you won&#8217;t convert directly to and from binary; you&#8217;ll convert to and from a sum of <a title="A Table of Nonnegative Powers of Two" href="http://www.exploringbinary.com/a-table-of-nonnegative-powers-of-two/">nonnegative powers of two</a>. It&#8217;s easier for humans to work that way, especially when doing calculations mentally. By converting a number to a sum of powers of two, you&#8217;ll have converted it to binary indirectly.  After all, binary integers are made up of a 1s place, a 2s place, a 4s place, an 8s place, etc. The machine is labeled as such to facilitate this form of conversion.</p>
<p>The powers of two present in a sum tell you where to place the marbles. For example, to enter the number 9, which equals 8 + 1, place a marble in the 8 and 1 slots. To enter the number 15, place marbles in the 8, 4, 2, and 1 slots. Any number between 1 and 63, if not already a power of two, can be converted to a sum of powers of two from this set: {1, 2, 4, 8, 16, 32}. <em>Each power of two can appear at most once.</em></p>
<p>(There is a systematic way to convert a decimal number to a sum of powers of two, but that&#8217;s beyond the scope of this article. For small numbers, such as those handled by this machine, you should be able to get by on trial and error.)</p>
<p>To interpret the result presented by the machine, simply do the reverse &#8212; add the resulting powers of two to come up with the decimal answer.</p>
<h3>Example</h3>
<p>If you want to add 13 to 44, perform the following steps:</p>
<ol>
<li>Push the result lever to set the machine&#8217;s memory to 0.</li>
<li>Load 13 into the input tray and push the input lever to add it to 0 (13 = 8 + 4 + 1 = 1101).</li>
<li>Load 44 into the input tray and push the input lever to add it to 13 (44 = 32 + 8 + 4 = 101100).</li>
<li>Push the result lever to get the result of 57 (111001 = 32 + 16 + 8 + 1 = 57).</li>
<li>Pull the result lever to clear the result from the output tray.</li>
</ol>
<div class="wp-caption aligncenter" style="width: 410px"><img class="centered" title="Marble Adder I/O Example." src="http://www.exploringbinary.com/wp-content/uploads/Marble-Adder-IO.jpg" alt="Marble Adder I/O Example." width="400" height="362" /><p class="wp-caption-text">001101 + 101100 = 111001, or 13 + 44 = 57.</p></div>
<h2>Binary Logic</h2>
<p>The key component of the logic of the machine is the rocker. The rocker serves both as one bit of memory and a carry mechanism for addition. Each rocker has two stable positions, rocked left and rocked right; rocked left represents 0, and rocked right represents 1. The six rockers give 2<sup>6</sup>, or 64, states in total. These states correspond to the binary representations of the numbers 0 to 63. </p>
<p>For example:</p>
<div class="wp-caption alignleft" style="width: 233px"><img class="alignleft" title="Marble adder stores 0." src="http://www.exploringbinary.com/wp-content/uploads/Marble-Adder-Rockers-0.jpg" alt="Marble adder stores 0." width="223" height="260" /><p class="wp-caption-text">Marble adder stores 0.</p></div>
<div class="wp-caption alignright" style="width: 235px"><img class="alignright" title="Marble adder stores 111111, or 63." src="http://www.exploringbinary.com/wp-content/uploads/Marble-Adder-Rockers-63.jpg" alt="Marble adder stores 111111, or 63." width="225" height="260" /><p class="wp-caption-text">Marble adder stores 111111, or 63.</p></div>
<div class="wp-caption alignleft" style="width: 233px"><img class="alignleft" title="Marble adder stores 10101, or 21." src="http://www.exploringbinary.com/wp-content/uploads/Marble-Adder-Rockers-21.jpg" alt="Marble adder stores 10101, or 21." width="223" height="260" /><p class="wp-caption-text">Marble adder stores 10101, or 21.</p></div>
<div class="wp-caption alignright" style="width: 236px"><img class="alignright" title="Marble adder stores 101000, or 40." src="http://www.exploringbinary.com/wp-content/uploads/Marble-Adder-Rockers-40.jpg" alt="Marble adder stores 101000, or 40." width="226" height="260" /><p class="wp-caption-text">Marble adder stores 101000, or 40.</p></div>
<p class="clear_with_padding">When a marble falls on a rocker, the rocker toggles. If it&#8217;s rocked left before the marble lands on it, it rocks right; if it&#8217;s rocked right before the marble lands on it, it rocks left. In the latter case, the falling marble is channeled through a hole to the next rocker, where this process is repeated. The cascading of rockers continues until a left rocked rocker is reached (if there is none, that&#8217;s overflow, and the marble just falls out of the machine).</p>
<p>The action of the falling marbles on the rockers is the mechanical analog of binary addition. A falling marble represents a 1. When added to 0, the result is 1. When added to 1, the result is 0, with a carry of 1 to the next position. The carry propagates until a 0 bit is reached.</p>
<h2>Examples in the Video</h2>
<p>Matthias goes through six examples in the video &#8212; here is my analysis of each (time stamps are noted in parentheses):</p>
<ol>
<li><strong>1 + 1 + 1 + 1 = 4</strong> (0:00-0:47).
<p>This shows how to use the machine to count; that is, by adding 1 repeatedly.</p>
</li>
<li><strong>5 + 6 + 7 = 18</strong> (0:48-1:27).
<p>This is an example of adding three numbers.</p>
</li>
<li><strong>21 + 6 + 13 = 40</strong> (1:28-1:55).
<p>This is another example of adding three numbers.</p>
</li>
<li><strong>31 + 1 = 32</strong> (1:56-2:22).
<p>This shows a long cascade of marbles, which is easy to see in binary: 11111 + 1 = 100000. The added 1 carries all the way to the 6th place.</p>
</li>
<li><strong>31 + 31 = 62</strong> (2:23-2:55).
<p>This shows what happens when you double a number &#8212; it shifts the entire number one bit to the left. In binary, you see that 11111 becomes 111110.</p>
</li>
<li><strong>63 + 1 = 0</strong> (2:56-3:25).
<p>This demonstrates overflow, which in this case results in 0; 64 mod 64 = 0.</p>
</li>
</ol>
<h2>Using the Machine to Subtract</h2>
<p>You can use the machine to subtract if you represent binary numbers using complement notation; for example, <a title="Wikipedia article on two’s complement" href="http://en.wikipedia.org/wiki/Two%27s_complement">two&#8217;s complement</a>. Two&#8217;s complement encodes negative numbers as well as positive numbers, allocating the 64 binary values to the numbers -32 through 31. The numbers 0 through 31 keep their normal binary form, 0 through 11111. The numbers -32 to -1 are assigned the values 100000 through 111111, respectively.</p>
<p>In two&#8217;s complement, the negative of a number is computed by inverting its bits and adding 1 (all 6 bits must be inverted, including leading zeros). For example, to compute -31,</p>
<ol>
<li>Compute the binary representation of 31, which is 011111.</li>
<li>Invert the bits, getting 100000.</li>
<li>Add 1, getting 100001 = -31.</li>
</ol>
<p>You can subtract <em>b</em> from <em>a</em> by adding the two&#8217;s complement of <em>b</em> to <em>a</em>. For example, 31 &#8211; 31 = 11111 + 100001 = 1000000. That&#8217;s 7 bits, but thanks to overflow, the machine gives the correct answer &#8212; 0.</p>
<h2>Comparison to a Digital Computer</h2>
<p>The machine functions like an accumulator and a ripple-carry adder. An accumulator is a register inside a microprocessor that stores a value and is modified with arithmetic, and a ripple-carry adder is a collection of logic gates that add individual bits and propagates carries sequentially.</p>
<p>To add two numbers in an accumulator, you would write assembly-language code like this:<br />
<code><br />
mov ax,0 ; set accumulator to 0<br />
add ax,00001101b  ; add 13<br />
add ax,00101100b  ; add 44<br />
mov bx,ax      ; store result (57)<br />
</code></p>
<p>Here are some other similarities and differences between the marble adding machine and a digital computer:</p>
<ul>
<li>The machine&#8217;s register size is much smaller &#8212; it has 6 bits instead of 32 or 64.</li>
<li>The machine&#8217;s memory is non-volatile (retains its value without power), unlike a register inside a microprocessor.</li>
<li>The logic of the machine is not based on logic gates (AND, OR, NOT, etc.) like a microprocessor. However, the logic is binary, based on the two states of each rocker.</li>
<li>The machine, like a microprocessor, can subtract by adding two&#8217;s complement numbers.</li>
<li>The user of the machine must convert between decimal and binary, unlike in a general purpose computer, where this can be done automatically.</li>
</ul>
<h2>For More Information</h2>
<p>Go to Matthias&#8217; web page, <a title="&ldquo;More on the Binary Marble Adding Machine&rdquo;" href="http://woodgears.ca/marbleadd/more.html">&#8220;More on the Binary Marble Adding Machine&#8221;</a>, for details on how the machine is constructed. He discusses details like how he keeps marbles from falling out, how two marbles can land on a rocker in quick succession and still toggle it correctly, etc.</p>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/the-binary-marble-adding-machine/">The Binary Marble Adding Machine</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/the-binary-marble-adding-machine/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

