Difference between revisions of "CSC103: DT's Notes 1"
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 | |
− | + | ! | the |-symbol shows 9 ''rolling over'' to 0 | |
− | + | ! | the !-symbol shows that as 9 rolls over, its left neighbor gets incremented by 1 | |
− | + | 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 | |
− | 000 | + | 000 00000 |
− | 001 | + | 001 00001 |
− | 002 | + | 002 00010 |
− | 003 | + | 003 00011 |
− | 004 | + | 004 00100 |
− | 005 | + | 005 00101 |
− | 006 | + | 006 00110 |
− | 007 | + | 007 00111 |
− | 008 | + | 008 01000 |
− | 009 | + | 009 01001 |
− | 010 | + | 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> | |
− | + | ||
− | + | = 1 x 1000 + 2 x 100 + 4 x 10 + 7 x 1 | |
− | + | = 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 | |
− | + | | |
− | + | = 16 + 8 + 0 + 0 + 1 | |
− | + | | |
+ | = 25 in decimal | ||
<br /> | <br /> | ||
Line 322: | Line 325: | ||
The result: | The result: | ||
− | + | 1 3 3 | |
− | + | + 3 8 5 | |
− | + | ------------ | |
− | + | <font color="magenta">5</font> 1 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 | |
− | + | + 0010110 | |
− | + | ------------ | |
− | + | ||
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 | |
− | + | + 0010110 | |
− | + | ------------ | |
− | + | 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 | |
− | + | 1 <---- we start here, and go down by 1 | |
− | + | ------ | |
− | + | <font color="red">1</font> <font color="magenta">0</font> +1 | |
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> | |
− | + | 1010011 | |
− | + | + 0010110 | |
− | + | ------------ | |
− | + | <font color="magenta">0</font>1 | |
Continuing this we finally get | Continuing this we finally get | ||
− | + | 1 | |
− | + | 1010011 | |
− | + | + 0010110 | |
− | + | ------------ | |
− | + | 1101001 | |
Revision as of 18:13, 22 September 2013
--© D. Thiebaut 08:10, 30 January 2012 (EST)