1 00:00:07,410 --> 00:00:09,240 NATE HARDISON: Back when you learned how to read and write 2 00:00:09,240 --> 00:00:14,240 numbers, you learned about the digits 0 to 9. 3 00:00:14,240 --> 00:00:16,620 To write whole numbers larger than 9, you learned that all 4 00:00:16,620 --> 00:00:19,610 you had to do was use some combination of these digits, 5 00:00:19,610 --> 00:00:26,780 as in 52 and 437. 6 00:00:26,780 --> 00:00:31,400 So this way of writing numbers has a name, decimal notation. 7 00:00:31,400 --> 00:00:32,530 >> Why decimal? 8 00:00:32,530 --> 00:00:36,100 Well, the Latin root of decimal, "decem," means 10. 9 00:00:36,100 --> 00:00:38,970 And when you have 10 digits in your notation system, 10 10 00:00:38,970 --> 00:00:41,090 becomes a rather special number. 11 00:00:41,090 --> 00:00:44,720 Let's look at the number 437 written in decimal notation to 12 00:00:44,720 --> 00:00:46,110 understand why. 13 00:00:46,110 --> 00:00:55,990 We can first break up 437 into 400 plus 30 plus 7. 14 00:00:55,990 --> 00:01:01,900 >> We can take it apart even more so that we've got 4 times 100 15 00:01:01,900 --> 00:01:08,780 plus 3 times 10 plus 7 times 1. 16 00:01:08,780 --> 00:01:11,760 Remember learning about the ones place, the tens place, 17 00:01:11,760 --> 00:01:13,840 the hundreds place, and so on? 18 00:01:13,840 --> 00:01:16,780 This is exactly where that comes from. 19 00:01:16,780 --> 00:01:19,540 And finally, we can see how we've got a bunch of powers of 20 00:01:19,540 --> 00:01:21,550 10 embedded in here. 21 00:01:21,550 --> 00:01:31,160 We've got 4 times 10 to the 2 plus 3 times 10 to the 1 plus 22 00:01:31,160 --> 00:01:35,380 7 times 10 to the 0. 23 00:01:35,380 --> 00:01:37,120 So now you see why 10 is a special 24 00:01:37,120 --> 00:01:39,030 number in decimal notation. 25 00:01:39,030 --> 00:01:42,310 In fact, we've got a name for it, it's called the base since 26 00:01:42,310 --> 00:01:45,750 it's the base of the exponent in our arithmetic here. 27 00:01:45,750 --> 00:01:48,970 >> Decimal notation is not the only way to represent numbers. 28 00:01:48,970 --> 00:01:53,810 In fact, even if we get rid of the digits 2 through 9, we can 29 00:01:53,810 --> 00:01:55,400 still represent all of the numbers that 30 00:01:55,400 --> 00:01:57,400 we could with decimal. 31 00:01:57,400 --> 00:02:01,640 So now that we have two digits, 0 and 1, 2 is our 32 00:02:01,640 --> 00:02:04,880 special number, the base of our notation system. 33 00:02:04,880 --> 00:02:08,110 The name of this notation system is called binary, since 34 00:02:08,110 --> 00:02:10,680 the prefix "bi" means two. 35 00:02:10,680 --> 00:02:13,920 So instead now of having a ones place and tens place and 36 00:02:13,920 --> 00:02:17,760 so on, we now have a ones place, a twos place, a fours 37 00:02:17,760 --> 00:02:21,210 place, and so on, going up by powers of two. 38 00:02:21,210 --> 00:02:23,140 So let's see this by doing some counting. 39 00:02:23,140 --> 00:02:28,580 So 0 still 0, and 1 is still 1. 40 00:02:28,580 --> 00:02:31,480 >> However, now that we've got a twos place instead of a tens 41 00:02:31,480 --> 00:02:36,850 place, 10 represents the number 2. 42 00:02:36,850 --> 00:02:41,890 To get 3, we add 1 to that and get 11. 43 00:02:41,890 --> 00:02:48,320 4, since there's now a fours place, is represented by 100. 44 00:02:48,320 --> 00:02:53,070 Five is 101. 45 00:02:53,070 --> 00:02:56,912 6 is 110. 46 00:02:56,912 --> 00:03:00,270 7 is 111. 47 00:03:00,270 --> 00:03:06,450 8, again, has its own place, so it's 1000. 48 00:03:06,450 --> 00:03:08,770 And I think you get the point. 49 00:03:08,770 --> 00:03:11,060 Let's take a stab at reading a large binary number and 50 00:03:11,060 --> 00:03:13,610 turning it back into decimal notation, since that's what 51 00:03:13,610 --> 00:03:14,240 we're used to. 52 00:03:14,240 --> 00:03:22,120 This number, in binary, reads 101110011. 53 00:03:22,120 --> 00:03:24,860 >> To figure out its decimal representation, let's start by 54 00:03:24,860 --> 00:03:27,760 writing the places under each of the digits. 55 00:03:27,760 --> 00:03:31,640 To start, we have the 2 to the zeros place on the far right, 56 00:03:31,640 --> 00:03:36,426 followed by the 2 the ones place, 2 to the twos place, 2 57 00:03:36,426 --> 00:03:43,823 to the three, 2 to the four, 2 to the five, 2 to the six, 2 58 00:03:43,823 --> 00:03:50,000 to the seven, and finally, all the way up to 2 to the eight. 59 00:03:50,000 --> 00:03:54,970 Now if we do the math, that's the ones place, the twos 60 00:03:54,970 --> 00:04:01,410 place, the fours place, the eights place, the 16ths place, 61 00:04:01,410 --> 00:04:09,280 the 32nds place, 64ths place, 128ths place, and finally the 62 00:04:09,280 --> 00:04:11,520 256ths place. 63 00:04:11,520 --> 00:04:13,160 Whew. 64 00:04:13,160 --> 00:04:15,240 So now, if we start multiplying everything 65 00:04:15,240 --> 00:04:25,150 together, we see we have 1 times 256 plus 1 times 64 plus 66 00:04:25,150 --> 00:04:40,280 1 times 32 plus 1 times 16 plus 1 times 2 and 1 times 1. 67 00:04:40,280 --> 00:04:44,810 >> So if we sum all of that together, we get to 256 plus 68 00:04:44,810 --> 00:04:50,450 64 plus 32 plus 16 plus 2 plus 1, all for a 69 00:04:50,450 --> 00:04:54,750 grand total of 371. 70 00:04:54,750 --> 00:04:57,340 Translating from decimal notation to binary notation is 71 00:04:57,340 --> 00:04:59,810 somewhat tricky, since we need to go from a number that's 72 00:04:59,810 --> 00:05:03,650 based on powers of 10 to one that's based on powers of 2. 73 00:05:03,650 --> 00:05:05,170 Let's give it go. 74 00:05:05,170 --> 00:05:08,575 Here we have the number 237 in decimal notation. 75 00:05:11,400 --> 00:05:14,190 To translate into binary notation, I start by finding 76 00:05:14,190 --> 00:05:21,960 the largest power of 2 that's less than it, which is 128. 77 00:05:21,960 --> 00:05:24,880 I put a 1 in the one hundred twenty-eighths place down here 78 00:05:24,880 --> 00:05:26,460 in my binary number. 79 00:05:26,460 --> 00:05:35,820 And then I subtract 128 from 237, and I get 109. 80 00:05:35,820 --> 00:05:37,900 Then I just repeat the process. 81 00:05:37,900 --> 00:05:42,110 The largest power of 2 that's smaller than 109 is 64, so I 82 00:05:42,110 --> 00:05:45,040 put a 1 in the 64ths place and subtract 64 83 00:05:45,040 --> 00:05:55,760 from 109 to get 45. 84 00:05:55,760 --> 00:06:00,540 Again, the largest power of 2 that's less than 45 is 32, so 85 00:06:00,540 --> 00:06:05,750 put a 1 in the appropriate slot and subtract 32-- 86 00:06:05,750 --> 00:06:07,000 I'm going to move up here-- 87 00:06:09,350 --> 00:06:12,340 to get 13. 88 00:06:12,340 --> 00:06:14,900 >> Moving on, I get 8 as the largest power 89 00:06:14,900 --> 00:06:17,020 of 2 now, not 16. 90 00:06:17,020 --> 00:06:21,390 So I put a 0 in the 16s place, a 1 in the 8s place, 91 00:06:21,390 --> 00:06:25,870 subtract, and get 5. 92 00:06:25,870 --> 00:06:27,940 Then 4 is the largest power of 2. 93 00:06:27,940 --> 00:06:29,855 I subtract and get 1. 94 00:06:34,610 --> 00:06:37,160 Now I can finish off the translation easily. 95 00:06:37,160 --> 00:06:42,100 I put a 0 in the twos place, and put a 1 in the ones place. 96 00:06:42,100 --> 00:06:47,624 The result, 11101101. 97 00:06:47,624 --> 00:06:50,200 >> One thing you might not have expected is that all of the 98 00:06:50,200 --> 00:06:53,850 algorithms you learned to add, subtract, multiply, and divide 99 00:06:53,850 --> 00:06:56,940 in decimal notation work in binary notation as well. 100 00:06:56,940 --> 00:06:58,850 We'll do an example of addition. 101 00:06:58,850 --> 00:07:09,230 Here we've got 1101101 plus 1010110. 102 00:07:09,230 --> 00:07:12,330 Just as in decimal addition, we'll start from the right and 103 00:07:12,330 --> 00:07:14,040 work our way to the left. 104 00:07:14,040 --> 00:07:16,840 The only difference is that we carry a 1 if the two digits 105 00:07:16,840 --> 00:07:20,030 we're adding have a sum greater than 1, instead of a 106 00:07:20,030 --> 00:07:23,490 sum greater than 9, as in decimal. 107 00:07:23,490 --> 00:07:27,680 So on the right, we have 1 plus 0, 1. 108 00:07:27,680 --> 00:07:32,820 >> Moving to the left, we have 0 plus 1, again 1. 109 00:07:32,820 --> 00:07:36,770 Moving left again, we have 1 plus 1, we write a 0, 110 00:07:36,770 --> 00:07:38,920 and we carry a 1. 111 00:07:38,920 --> 00:07:45,680 Then we have 1, 1, 0, so we have a 0, carry a 1. 112 00:07:45,680 --> 00:07:49,960 Then 1, 0, 1, again 0, carry a 1. 113 00:07:49,960 --> 00:07:54,890 1, 1, 0, 0 again, carry a final 1. 114 00:07:54,890 --> 00:07:58,810 >> And finally, 1, 1, 1, so we have a 1 and a 115 00:07:58,810 --> 00:08:01,020 final 1 on the left. 116 00:08:01,020 --> 00:08:06,340 The result, 11000011. 117 00:08:06,340 --> 00:08:07,380 And that concludes our quick 118 00:08:07,380 --> 00:08:09,580 introduction to binary notation. 119 00:08:09,580 --> 00:08:13,550 >> My name is Nate Hardison, and this is CS 50.