<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="m10206">

<name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">The Mathematics of Computing</name>

<metadata xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
  <md:version xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">2.2</md:version>
  <md:created xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">2001/07/17</md:created>
  <md:revised xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">2004/08/10 13:20:39.652 GMT-5</md:revised>
  <md:authorlist xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
      <md:author xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="dhj">
      <md:firstname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Don</md:firstname>
      
      <md:surname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Johnson</md:surname>
      <md:email xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">dhj@rice.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
    <md:maintainer xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="dhj">
      <md:firstname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Don</md:firstname>
      
      <md:surname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Johnson</md:surname>
      <md:email xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">dhj@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="mrshawn">
      <md:firstname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Shawn</md:firstname>
      
      <md:surname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Stewart</md:surname>
      <md:email xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">mrshawn@alumni.rice.edu</md:email>
    </md:maintainer>
    <md:maintainer xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="jac3">
      <md:firstname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">John</md:firstname>
      <md:othername xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Austin</md:othername>
      <md:surname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Cottrell</md:surname>
      <md:email xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">jac3@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">digital signal processing</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">digital processing systems</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">binary</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">base 2</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">bit</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">binary logic</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">logic</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">logical operators</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">floating point</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">word length</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">bit representation</md:keyword>
  </md:keywordlist>

  <md:abstract xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">An introduction to the mathematics used by computers. Topics include, Base 2, a very short overview of logical operators and how they relate to binary addition, and information on bit representations of real numbers.</md:abstract>
</metadata>
<content xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">


<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="p1"> 
We need to concentrate on how computers represent numbers and perform arithmetic. Suppose we have twenty-six "things."  This number is an abstract quantity that we need to represent so that we can perform calculations on it.  We represent this number with <term xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">positional notation</term> using base 10:
<m:math>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:ci>
    <m:msub>
    <m:mn>26</m:mn>
    <m:mn>10</m:mn>
    </m:msub>
    </m:ci>
  </m:apply>
  <m:apply>
    <m:plus/>
    <m:apply>
      <m:times/>
      <m:cn>2</m:cn>
      <m:ci>·</m:ci>
      <m:ci>
        <m:msup>
        <m:mn>10</m:mn>
        <m:mn>1</m:mn>
        </m:msup>
      </m:ci>
    </m:apply>
    <m:apply>
    <m:times/>
      <m:cn>6</m:cn>
      <m:ci>·</m:ci>
      <m:ci>
        <m:msup>
        <m:mn>10</m:mn>
        <m:mn>0</m:mn>
        </m:msup>
      </m:ci>
    </m:apply>
  </m:apply>
</m:apply>
</m:math>
.  We could also use base-8 notation ( 
<m:math> 
<m:apply>
  <m:eq/>
  <m:apply>
    <m:ci>
    <m:msub>
    <m:mn>32</m:mn>
    <m:mn>8</m:mn>
    </m:msub>
    </m:ci>
  </m:apply>
  <m:apply>
    <m:plus/>
    <m:apply>
      <m:times/>
      <m:cn>3</m:cn>
      <m:ci>·</m:ci>
      <m:ci>
        <m:msup>
        <m:mn>8</m:mn>
        <m:mn>1</m:mn>
        </m:msup>
      </m:ci>
    </m:apply>
    <m:apply>
    <m:times/>
      <m:cn>2</m:cn>
      <m:ci>·</m:ci>
      <m:ci>
        <m:msup>
        <m:mn>8</m:mn>
        <m:mn>0</m:mn>
        </m:msup>
      </m:ci>
    </m:apply>
  </m:apply>
</m:apply>
</m:math>
), base 16 ( 
<m:math>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:times/>
    <m:cn>1</m:cn>
    <m:ci>A</m:ci>
  </m:apply>
  <m:apply>
    <m:plus/>
    <m:apply>
      <m:times/>
      <m:cn>1</m:cn>
      <m:ci>·</m:ci>
      <m:ci>
        <m:msup>
        <m:mn>16</m:mn> 
        <m:mn>1</m:mn>
        </m:msup>
      </m:ci>
    </m:apply>
    <m:apply>
      <m:times/>
      <m:ci>A</m:ci>
      <m:ci>·</m:ci>
      <m:ci>
        <m:msup>
        <m:mn>16</m:mn>
        <m:mn>0</m:mn>
        </m:msup>
      </m:ci>
    </m:apply>
  </m:apply>
</m:apply>
</m:math>
, with 
<m:math>
<m:ci>A</m:ci>
</m:math> 
representing ten), or base 2 ( 
<m:math>
<m:apply>
  <m:eq/>
  <m:ci>
    <m:msub>
    <m:mn>11010</m:mn>
    <m:mn>2</m:mn>
    </m:msub>
  </m:ci>
  <m:apply>
    <m:plus/>
    <m:apply>
      <m:times/>
      <m:cn>1</m:cn>
      <m:ci>·</m:ci>
      <m:ci>
        <m:msup>
        <m:mn>2</m:mn>
        <m:mn>4</m:mn>
        </m:msup>
      </m:ci>
    </m:apply>
    <m:apply>
      <m:times/>
      <m:cn>1</m:cn>
      <m:ci>·</m:ci>
      <m:ci>
        <m:msup>
        <m:mn>2</m:mn>
        <m:mn>3</m:mn>
        </m:msup>
      </m:ci>
    </m:apply>
    <m:apply>
      <m:times/>
      <m:cn>0</m:cn>
      <m:ci>·</m:ci>
      <m:ci>
        <m:msup>
        <m:mn>2</m:mn>
        <m:mn>2</m:mn>
        </m:msup>
      </m:ci>
    </m:apply>
   <m:apply>
      <m:times/>
      <m:cn>1</m:cn>
      <m:ci>·</m:ci>
      <m:ci>
        <m:msup>
        <m:mn>2</m:mn>
        <m:mn>1</m:mn>
        </m:msup>
      </m:ci>
    </m:apply>
    <m:apply>
      <m:times/>
      <m:cn>0</m:cn>
      <m:ci>·</m:ci>
      <m:ci>
        <m:msup>
        <m:mn>2</m:mn>
        <m:mn>0</m:mn>
        </m:msup>
      </m:ci>
    </m:apply>
  </m:apply>
</m:apply>
</m:math>
).  Each of these represent the <emphasis xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">same</emphasis> quantity; all numbers can be so represented and arithmetic can be performed in each system.  Which we chose is a matter of convenience and cultural heritage.  Each position is occupied by an integer between 0 and the base minus 1, and the integer's position implicitly represents how many times the base raised to an exponent is needed.  The integer 
<m:math>
<m:ci>N</m:ci>
</m:math> 
is succinctly expressed in base-b as 
<m:math>
<m:apply>
  <m:eq/>
  <m:ci>
    <m:msub>
    <m:mi>N</m:mi>
    <m:mi>b</m:mi>
    </m:msub>
  </m:ci>
  <m:apply>
    <m:times/>
    <m:ci>
      <m:msub>
      <m:mi>d</m:mi>
      <m:mi>n</m:mi>
      </m:msub>
    </m:ci>
    <m:ci>
      <m:msub>
      <m:mi>d</m:mi>
      <m:mi>n-1</m:mi>
      </m:msub>
    </m:ci>
    <m:ci>…</m:ci>
    <m:ci>
      <m:msub>
      <m:mi>d</m:mi>
      <m:mi>0</m:mi>
      </m:msub>
    </m:ci>  
  </m:apply>
</m:apply>  
</m:math>
, which mathematically means 
<m:math>
<m:apply>
  <m:eq/>
  <m:ci>
    <m:msub>
    <m:mi>N</m:mi>
    <m:mi>b</m:mi>
    </m:msub>
  </m:ci>
  <m:apply>
    <m:plus/>
    <m:apply>
      <m:times/>
      <m:ci>
        <m:msub>
        <m:mi>d</m:mi>
        <m:mi>n</m:mi>
        </m:msub>
      </m:ci>
      <m:apply>
        <m:power/>
        <m:ci>b</m:ci>
        <m:ci>n</m:ci>
      </m:apply>
    </m:apply>
    <m:ci>…</m:ci>
    <m:apply>
      <m:times/>
      <m:ci>
        <m:msub>
        <m:mi>d</m:mi>
        <m:mn>0</m:mn>
        </m:msub>
      </m:ci>
      <m:apply>
        <m:power/>
        <m:ci>b</m:ci>
        <m:cn>0</m:cn>
      </m:apply>
    </m:apply>
  </m:apply>
</m:apply>
</m:math>
.  No matter what base you might choose, addition, subtraction, multiplication, and division all follow the same rules you learned as a child.  These rules can be derived mathematically from the positional notation conventions defined by this formula.  (Non-positional systems are very strange; take Roman numerals for example.  Try adding (or, more extremely, dividing) two numbers using this number representation system).  To extend the positional representation to signed integers, we add a symbol that represents whether the number is positive or negative.  
</para>

<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="p2">
Humans have ten fingers, and so it's not so surprising that many cultures throughout history have used base 10.  Digital computers use base 2 or <term xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">binary</term> number representation, each digit of which is known as a <term xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">bit</term> (<emphasis xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">b</emphasis>inary dig <emphasis xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">it</emphasis>).  Here, each bit is represented as a voltage that is either "high" or "low," thereby representing "1" or "0", respectively.  To represent signed values, we tack on a special bit -- the <term xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">sign bit</term> -- to express the sign.  The binary addition and multiplication tables are

<equation xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="eqn0000">
<m:math>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:plus/>
    <m:cn>0</m:cn>
    <m:cn>0</m:cn>
  </m:apply>
  <m:cn>0</m:cn>
</m:apply>
<m:ci>,</m:ci>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:plus/>
    <m:cn>1</m:cn>
    <m:cn>1</m:cn>
  </m:apply>
  <m:cn>10</m:cn>
</m:apply>
<m:ci>,</m:ci>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:plus/>
    <m:cn>0</m:cn>
    <m:cn>1</m:cn>
  </m:apply>
  <m:cn>1</m:cn>
</m:apply>
<m:ci>,</m:ci>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:plus/>
    <m:cn>1</m:cn>
    <m:cn>0</m:cn>
  </m:apply>
  <m:cn>1</m:cn>
</m:apply>
<m:ci>,</m:ci>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:times/>
    <m:cn>0</m:cn>
    <m:ci>·</m:ci>
    <m:cn>0</m:cn>
  </m:apply>
  <m:cn>0</m:cn>
</m:apply>
<m:ci>,</m:ci>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:times/>
    <m:cn>0</m:cn>
    <m:ci>·</m:ci>
    <m:cn>1</m:cn>
  </m:apply>
  <m:cn>0</m:cn>
</m:apply>
<m:ci>,</m:ci>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:times/>
    <m:cn>1</m:cn>
    <m:ci>·</m:ci>
    <m:cn>1</m:cn>
  </m:apply>
  <m:cn>1</m:cn>
</m:apply>
<m:ci>,</m:ci>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:times/>
    <m:cn>1</m:cn>
    <m:ci>·</m:ci>
    <m:cn>0</m:cn>
  </m:apply>
  <m:cn>0</m:cn>
</m:apply>   
<m:ci>.</m:ci>
</m:math>
</equation>
</para>

<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="p3">
A <term xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">carry</term> means that a computation performed at a given position affects other positions as well.  Here,
<m:math>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:plus/>
    <m:cn>1</m:cn>
    <m:cn>1</m:cn>
  </m:apply>
  <m:cn>10</m:cn>
</m:apply>
</m:math>
is an example of a computation that involves a carry. Note that if carries are ignored, subtraction of two single-digit binary numbers yields the same bit as addition.  Computers use high and low voltage values to express a bit, and an array of such voltages express numbers akin to positional notation. Logic circuits perform arithmetic operations.
</para>

<exercise xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="exer1">
    
<problem xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="prob1">
Add twenty-five and seven in base 2.  Note the carries that might occur.  Why is the result "nice"?
</para>
</problem>
    
<solution xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="sol">
<m:math>
<m:apply>
  <m:eq/>
  <m:ci>
    <m:msub>
    <m:mn>25</m:mn>
    <m:mn>10</m:mn>
    </m:msub>
  </m:ci>
  <m:ci>
  <m:msub>
    <m:mn>11001</m:mn>
    <m:mn>2</m:mn>
    </m:msub>
  </m:ci>
</m:apply>
</m:math>
and
<m:math>
<m:apply>
  <m:eq/>
  <m:ci>
    <m:msub>
    <m:mn>7</m:mn>
    <m:mn>10</m:mn>
    </m:msub>
  </m:ci>
  <m:ci>
  <m:msub>
    <m:mn>111</m:mn>
    <m:mn>2</m:mn>
    </m:msub>
  </m:ci>
</m:apply>
</m:math>
.  We find that
<m:math>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:plus/>
    <m:ci>
      <m:msub>
      <m:mn>11001</m:mn>
      <m:mn>2</m:mn>
      </m:msub>
    </m:ci>
    <m:ci>
      <m:msub>
      <m:mn>111</m:mn>
      <m:mn>2</m:mn>
      </m:msub>
    </m:ci>
  </m:apply>
  <m:ci>
    <m:msub>
    <m:mn>100000</m:mn>
    <m:mn>2</m:mn>
    </m:msub>
  </m:ci>
  <m:ci>
    <m:msub>
    <m:mn>32</m:mn>
    <m:mn>10</m:mn>
    </m:msub>
  </m:ci>
</m:apply>
</m:math>
.
</para>
</solution>
  
</exercise>

<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="p4"> 
Note that the logical operations of AND and OR are equivalent to binary addition (if carries are ignored).  When used, logical operators indicate truth or falsehood.  For example, the statement  
<m:math>
<m:apply>
  <m:and/>
  <m:ci>A</m:ci>
  <m:ci>B</m:ci>
</m:apply>
</m:math>
, which represents "A AND B", will be true if <emphasis xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">both</emphasis> A is true and B is true, and false otherwise.  You could use this kind of statement to tell a search engine that you want to restrict hits to cases where A and B occur together, and not other cases.  The statement
<m:math>
<m:apply>
  <m:or/>
  <m:ci>A</m:ci>
  <m:ci>B</m:ci>
</m:apply>
</m:math>
represents "A OR B".  It will be true if A is true, or B is true, or both, and false if A and B are both false.  Note that if we represent truth by a "1" and falsehood by a "0", binary multiplication corresponds to AND statements, and binary addition corresponds to OR.  The Irish mathematician George Boole discovered this equivalence in the mid-nineteenth century. It laid the foundation for what we now call Boolean algebra, which expresses logical statements as equations.  More importantly, any computer using base-2 representations and arithmetic can also easily evaluate logical statements. This fact makes an integer-based computational device much more powerful than might be immediately obvious.  
</para>

<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="p4.1"> Computers express numbers in a fixed-size collection of bits, commonly known as the computer's <term xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">word length</term>.  Today, word-lengths are either 32 or 64 bits, corresponding to a power-of-two number of bytes (8-bit "chunks").  This design choice restricts the largest integer (in magnitude) that can be represented on a computer.
</para>

<exercise xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="exer1.1">

<problem xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="prob1.1">
For both 32-bit and 64-bit integer representations, what is the largest number that can be represented? Don't forget that the sign bit must also be included.
</para>
</problem>
    
<solution xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="sol1.1">
For 
<m:math>
<m:ci>b</m:ci>
</m:math>
-bit signed integers, the largest number is 
<m:math>
<m:apply>
  <m:minus/>
  <m:apply>
    <m:power/>
    <m:cn>2</m:cn>
    <m:apply>
      <m:minus/>
      <m:ci>b</m:ci>
      <m:ci>1</m:ci>
    </m:apply>
  </m:apply>
  <m:cn>1</m:cn>
</m:apply>
</m:math>
.  For 
<m:math>
<m:apply>  
  <m:eq/>
  <m:ci>b</m:ci>
  <m:cn>32</m:cn>
</m:apply>
</m:math>
, we have 2,147,483,647, and for 
<m:math>
<m:apply>
  <m:eq/>
  <m:ci>b</m:ci>
  <m:cn>64</m:cn>
</m:apply>
</m:math>
, we have 9,223,372,036,854,775,807 or about 
<m:math>
<m:apply>
  <m:times/>
  <m:cn>9.2</m:cn>
  <m:ci>×</m:ci> 
  <m:apply>
    <m:power/>
    <m:cn>10</m:cn>
    <m:cn>18</m:cn>
  </m:apply>
</m:apply>
</m:math>
.
</para>
</solution>

</exercise>

<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="p4.2"> 
When it comes to expressing fractions, positional notation is easily extended to negative exponents using the decimal point convention:  Wherever the decimal point occurs in a string of digits, we know that the first digit to the left corresponds to the zero exponent, and the one to the right is
<m:math>
<m:apply>
  <m:minus/>
  <m:cn>1</m:cn>
</m:apply>
</m:math>
. In this way, we have 
<m:math>
<m:apply>
  <m:eq/>
  <m:ci>
    <m:msub>
    <m:mn>2.5</m:mn>
    <m:mn>10</m:mn>
    </m:msub>
  </m:ci>
  <m:apply>
    <m:plus/>
    <m:apply>
      <m:times/>
      <m:cn>2</m:cn>
      <m:ci>×</m:ci>
      <m:apply>
        <m:power/>
        <m:cn>10</m:cn>
        <m:cn>0</m:cn>
      </m:apply>
    </m:apply>
    <m:apply>
      <m:times/>
      <m:cn>5</m:cn>
      <m:ci>×</m:ci>
      <m:apply>
        <m:power/>
        <m:cn>10</m:cn>
        <m:cn>1</m:cn>
      </m:apply>
    </m:apply>
  </m:apply>
</m:apply>
</m:math>
.  Computers <emphasis xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">don't</emphasis> use this convention to represent numbers with fractional parts; instead, they use a generalization of scientific notation.  Here, a number (not necessarily an integer) x is expressed as 
<m:math>
<m:apply>
  <m:times/>
  <m:ci>m</m:ci>
  <m:ci>×</m:ci>
  <m:apply>
    <m:power/>
    <m:ci>b</m:ci>
    <m:ci>e</m:ci>
  </m:apply>
</m:apply>
</m:math>
, with the <term xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">mantissa</term> m lying within a proscribed range  (scientific notation requires 
<m:math>
<m:apply>
  <m:leq/>
  <m:cn>1</m:cn>
  <m:apply>
    <m:lt/>
    <m:apply>
      <m:abs/>
      <m:ci>m</m:ci>
    </m:apply>
    <m:cn>10</m:cn>
  </m:apply>
</m:apply>
</m:math>
), b is the base, and e is the <term xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">integer exponent</term>.  Computers use a convention known as <term xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">floating point</term>, where base 2 is used and the mantissa must lie between one-half and one.  Thus, two and one-half in the computer's number representation scheme becomes five-eighths times four: 
<m:math>
<m:apply>
  <m:times/>
  <m:cn>.101</m:cn>
  <m:ci>×</m:ci>
  <m:apply>
    <m:power/>
    <m:cn>2</m:cn>
    <m:cn>2</m:cn>
  </m:apply>
</m:apply>
</m:math>
.  The mantissa is stored in most of the bits in a computer's word, and the exponent stored in the remaining bits.  Both the exponent and mantissa have sign bits associated with them.  Thirty-two-bit floating point numbers, known as single-precision floating point, have eight bits representing the exponent (including the sign bit) and the remaining twenty-four representing the mantissa (again, also including a sign bit).
</para>

<exercise xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="exer2">

<problem xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="prob2">
What are the largest and smallest numbers that can be represented in 32-bit floating point?  64-bit floating point that has sixteen bits allocated to the exponent? Note that both exponent and mantissa require a sign bit.
</para>
</problem>

<solution xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="sol2">
In floating point, the number of bits in the exponent determines the largest and smallest representable numbers.  For 32-bit floating point, the largest (smallest) numbers are
<m:math>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:power/>
    <m:cn>2</m:cn>
    <m:apply>
      <m:times/>
      <m:ci>±</m:ci>
      <m:cn>127</m:cn>
    </m:apply>
  </m:apply>
  <m:apply>
    <m:times/>
    <m:cn>1.7</m:cn>
    <m:ci>×</m:ci>
    <m:apply>
      <m:power/>
      <m:cn>10</m:cn>
      <m:cn>38</m:cn>
    </m:apply>
    <m:ci>·</m:ci>
    <m:cn>5.9</m:cn>
    <m:ci>×</m:ci>
    <m:apply>
      <m:power/>
      <m:cn>10</m:cn>
      <m:cn>39</m:cn>
    </m:apply>
  </m:apply>
</m:apply>
</m:math>
.  For 64-bit floating point, the largest number is about 
<m:math>
<m:apply>
  <m:power/>
  <m:cn>10</m:cn>
  <m:cn>9863</m:cn>
</m:apply>
</m:math>
.
</para>
</solution>

</exercise>

<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="p4.3">
So long as the integers aren't too large, they can be represented exactly in a computer using the binary positional notation. Electronic circuits that make up the physical computer can add and subtract integers without error.  However, this statement isn't quite true; when does addition cause problems?  Floating point representation handles numbers with fractional parts, but only some with no error.  Similar to the integer case, the number could be too big or too small to be so represented. More fundamentally, <emphasis xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">many</emphasis> numbers cannot be accurately represented no matter how many bits are used for the exponent and mantissa.  For example, you know that the fraction
<m:math>
<m:apply>
  <m:divide/>
  <m:cn>1</m:cn>
  <m:cn>3</m:cn>
</m:apply>
</m:math>
has an infinite decimal (base 10) expansion; no matter how many decimal digits you have in your calculator, you will never represent
<m:math>
<m:apply>
  <m:divide/>
  <m:cn>1</m:cn>
  <m:cn>3</m:cn>
</m:apply>
</m:math>
with complete accuracy.  It also has an infinite binary expansion as well.
</para>

<exercise xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="exer3">

<problem xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="prob3">
Can
<m:math>
<m:apply>
  <m:divide/>
  <m:cn>1</m:cn>
  <m:cn>3</m:cn>
</m:apply>
</m:math>
be expressed in a finite number of digits in any base?  If so, what bases do the job?
</para>
</problem>

<solution xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="sol3">
If the base is a multiple of three, then 
<m:math>
<m:apply>
  <m:divide/>
  <m:cn>1</m:cn>
  <m:cn>3</m:cn>
</m:apply>
</m:math>
will have
	a finite expansion. For example, in base 3:   
<m:math>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:divide/>
    <m:cn>1</m:cn>
    <m:cn>3</m:cn>
  </m:apply>
  <m:ci>
    <m:msub>
    <m:mn>0.1</m:mn>
    <m:mn>3</m:mn>
    </m:msub>
  </m:ci>
</m:apply>
</m:math>
, and in base 6:  
<m:math>
<m:apply>
  <m:eq/>
  <m:apply>
    <m:divide/>
    <m:cn>1</m:cn>
    <m:cn>3</m:cn>
  </m:apply>
  <m:ci>
    <m:msub>
    <m:mn>0.2</m:mn>
    <m:mn>6</m:mn>
    </m:msub>
  </m:ci>
</m:apply>
</m:math>
.
</para>
</solution>

</exercise>

<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="p4.4">
Clearly, many numbers have infinite expansions, and this situation applies to binary expansions as well.  Consequently, number representation and arithmetic performed by a computer cannot be infinitely accurate in most cases.  The errors incurred in most calculations will be small, but this fundamental source of error can cause trouble at times.
</para>

</content>
</document>
