Difference between revisions of "CSC103: DT's Notes 1"

From dftwiki3
Jump to: navigation, search
Line 96: Line 96:
 
Ok, now an important point in the counting process.  We have written all 10 digits in the right-most position of our number.  Because we could increment this digit, we didn't have to change the digits on the left.  Now that we have reached 9, we need to ''roll over'' the list of digits.  We have to go from 9 back to 0.  Because of this roll-over, we have to ''increment'' (that means adding 1) the digit that is ''directly to the left of the one rolling over.''   
 
Ok, now an important point in the counting process.  We have written all 10 digits in the right-most position of our number.  Because we could increment this digit, we didn't have to change the digits on the left.  Now that we have reached 9, we need to ''roll over'' the list of digits.  We have to go from 9 back to 0.  Because of this roll-over, we have to ''increment'' (that means adding 1) the digit that is ''directly to the left of the one rolling over.''   
  
  0 0 9
+
  0  0  9
      ! |           the |-symbol shows 9 ''rolling over'' to 0
+
      !  |           the |-symbol shows 9 ''rolling over'' to 0
      ! |           the !-symbol shows that as 9 rolls over, its left neighbor gets incremented by 1
+
      !  |           the !-symbol shows that as 9 rolls over, its left neighbor gets incremented by 1
  0 0
+
  0  1  0 
 +
   
  
 
Let's continue:
 
Let's continue:
Line 177: Line 178:
 
Let's put the numbers we've generated in decimal and in binary next to each other:
 
Let's put the numbers we've generated in decimal and in binary next to each other:
  
decimal         binary
+
  decimal          binary
  000             00000
+
   000             00000
  001             00001
+
   001             00001
  002             00010
+
   002             00010
  003             00011
+
   003             00011
  004             00100
+
   004             00100
  005             00101
+
   005             00101
  006             00110
+
   006             00110
  007             00111
+
   007             00111
  008             01000
+
   008             01000
  009             01001
+
   009             01001
  010             01010
+
   010             01010
  ...
+
   ...
 +
  
 
<tanbox>
 
<tanbox>
Line 223: Line 225:
 
The value of 1247 is 1 x 1000 + 2 * 100 + 4 * 10 + 7 * 1.  The 1000, 100, 10, and 1 factors represent different powers of the base, 10.  We can also rewrite it as  
 
The value of 1247 is 1 x 1000 + 2 * 100 + 4 * 10 + 7 * 1.  The 1000, 100, 10, and 1 factors represent different powers of the base, 10.  We can also rewrite it as  
  
    1247 = 1 x 10<sup>3</sup> + 2 x 10<sup>2</sup> + 4 x 10<sup>1</sup> + 7 x 10<sup>0</sup>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1247&nbsp;=&nbsp;1&nbsp;x&nbsp;10<sup>3</sup>&nbsp;+&nbsp;2&nbsp;x&nbsp;10<sup>2</sup>&nbsp;+&nbsp;4&nbsp;x&nbsp;10<sup>1</sup>&nbsp;+&nbsp;7&nbsp;x&nbsp;10<sup>0</sup>
 
+
 
            = 1 x 1000 + 2 x 100 + 4 x 10 + 7 x 1
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;1&nbsp;x&nbsp;1000&nbsp;+&nbsp;2&nbsp;x&nbsp;100&nbsp;+&nbsp;4&nbsp;x&nbsp;10&nbsp;+&nbsp;7&nbsp;x&nbsp;1
            = 1247
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;1247
 +
  
  
Line 233: Line 236:
 
Let's try that for the binary number 11001.  The base is 2 in this case, so the value is computed as:
 
Let's try that for the binary number 11001.  The base is 2 in this case, so the value is computed as:
  
  11001 = 1 x 2<sup>4</sup> + 1 x 2<sup>3</sup> + 0 x 2<sup>2</sup> + 0 x 2<sup>1</sup> + 1 x 2<sup>0</sup>
 
 
   
 
   
        = 1 x 16 + 1 x 8 + 0 x 4 + 0 x 2 + 1 x 1
+
&nbsp;&nbsp;&nbsp;11001&nbsp;=&nbsp;1&nbsp;x&nbsp;2<sup>4</sup>&nbsp;+&nbsp;1&nbsp;x&nbsp;2<sup>3</sup>&nbsp;+&nbsp;0&nbsp;x&nbsp;2<sup>2</sup>&nbsp;+&nbsp;0&nbsp;x&nbsp;2<sup>1</sup>&nbsp;+&nbsp;1&nbsp;x&nbsp;2<sup>0</sup>&nbsp;
 
+
&nbsp;
        = 16 + 8 + 0 + 0 + 1
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;1&nbsp;x&nbsp;16&nbsp;+&nbsp;1&nbsp;x&nbsp;8&nbsp;+&nbsp;0&nbsp;x&nbsp;4&nbsp;+&nbsp;0&nbsp;x&nbsp;2&nbsp;+&nbsp;1&nbsp;x&nbsp;1
 
+
&nbsp;&nbsp;
        = 25 in decimal
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;16&nbsp;+&nbsp;8&nbsp;+&nbsp;0&nbsp;+&nbsp;0&nbsp;+&nbsp;1
 
+
&nbsp;&nbsp;&nbsp;
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;25&nbsp;in&nbsp;decimal
  
 
<br />
 
<br />
Line 322: Line 325:
 
The result:
 
The result:
  
    1 3 3
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;3&nbsp;3
  + 3 8 5
+
&nbsp;&nbsp;+&nbsp;&nbsp;3&nbsp;8&nbsp;5
  ------------
+
&nbsp;&nbsp;------------
    <font color="magenta">5</font> 1 8
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font&nbsp;color="magenta">5</font>&nbsp;1&nbsp;8
 +
  
 
If we find ourselves in the case where adding the leftmost digits creates a roll-over, we simply pad the numbers with 0 and we find the logic answer.
 
If we find ourselves in the case where adding the leftmost digits creates a roll-over, we simply pad the numbers with 0 and we find the logic answer.
Line 336: Line 340:
 
Ready to try this in binary?  Let's take two binary numbers and add them:
 
Ready to try this in binary?  Let's take two binary numbers and add them:
  
      1010011
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1010011
  + 0010110
+
&nbsp;&nbsp;&nbsp;+&nbsp;&nbsp;0010110
  ------------
+
&nbsp;&nbsp;------------
 
+
 
Our ''table of digits'' is now simpler:
 
Our ''table of digits'' is now simpler:
  
Line 348: Line 352:
 
Here we start with the leftmost column, start at 1 in the table and go down by 0.  The result is 1.  We don't move in the table:
 
Here we start with the leftmost column, start at 1 in the table and go down by 0.  The result is 1.  We don't move in the table:
  
      1010011
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1010011
  + 0010110
+
&nbsp;&nbsp;&nbsp;+&nbsp;&nbsp;0010110
  ------------
+
&nbsp;&nbsp;------------
        1
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;1
  
 
Done with the rightmost column.  We move to the next column and add 1 to 1 (don't think too fast and assume it's 2!  2 does not exist in our table of digits!)
 
Done with the rightmost column.  We move to the next column and add 1 to 1 (don't think too fast and assume it's 2!  2 does not exist in our table of digits!)
  
    0
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0
    1   &lt;---- we start here, and go down by 1
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&lt;----&nbsp;we&nbsp;start&nbsp;here,&nbsp;and&nbsp;go&nbsp;down&nbsp;by&nbsp;1
  ------
+
&nbsp;&nbsp;------
  <font color="red">1</font> <font color="magenta">0</font>   +1  
+
&nbsp;&nbsp;&nbsp;<font&nbsp;color="red">1</font>&nbsp;<font&nbsp;color="magenta">0</font>&nbsp;&nbsp;&nbsp;&nbsp;+1&nbsp;&nbsp;&nbsp;
  
 
We had to roll-over in the table.  Therefore we take a ''carry'' of  1 and add it to the column on the left.
 
We had to roll-over in the table.  Therefore we take a ''carry'' of  1 and add it to the column on the left.
 
      
 
      
      <font color="red">1</font>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<font&nbsp;color="red">1</font>
      1010011
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1010011
  + 0010110
+
&nbsp;&nbsp;&nbsp;+&nbsp;&nbsp;0010110
  ------------
+
&nbsp;&nbsp;------------
        <font color="magenta">0</font>1
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<font&nbsp;color="magenta">0</font>1
  
 
Continuing this we finally get  
 
Continuing this we finally get  
  
  
      1
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;1
      1010011
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1010011
  + 0010110
+
&nbsp;&nbsp;&nbsp;+&nbsp;&nbsp;0010110
  ------------
+
&nbsp;&nbsp;------------
    1101001
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1101001
  
  

Revision as of 18:13, 22 September 2013

--© D. Thiebaut 08:10, 30 January 2012 (EST)



This section is only visible to computers located at Smith College













.