1 00:00:00,012 --> 00:00:04,916 In this video, we're going to talk about how computations are formed on computers. 2 00:00:04,916 --> 00:00:08,942 And, in particular, how numbers are represented on by computers. 3 00:00:08,942 --> 00:00:13,206 Turns out this is going to be very important for us to figure out how 4 00:00:13,206 --> 00:00:18,019 computers function so we can convert from analog signals to digital signals, 5 00:00:18,019 --> 00:00:22,908 understand the nature of the errors that are involved, and also the nature of the 6 00:00:22,908 --> 00:00:27,454 errors that are involved in when you do computations on digital computers. 7 00:00:27,454 --> 00:00:32,184 So, the first thing we need to talk about is what's called Positional Notation. 8 00:00:32,184 --> 00:00:37,157 This amounts to something we're very familiar with. And it turns out, how we 9 00:00:37,157 --> 00:00:42,515 deal with numbers is very similar to how computers deal with numbers, at least in 10 00:00:42,515 --> 00:00:46,219 a conceptual way. We'll talk about Base-2, which is the 11 00:00:46,219 --> 00:00:51,453 number system that computers use, and I'm going to emphasize that knowing your 12 00:00:51,453 --> 00:00:55,846 powers of two is going to be very, very useful skill to have. 13 00:00:55,846 --> 00:01:01,615 So, let's talk about positional notation. Now, I claim that one of the critical 14 00:01:01,615 --> 00:01:05,792 discoveries in mathematics was positional notation. 15 00:01:05,792 --> 00:01:11,163 So, what positional notation means is that we have a number that we would 16 00:01:11,163 --> 00:01:16,802 write, 257. What that means is that the 2 means 17 00:01:16,802 --> 00:01:24,567 2*100. So, 2*100 + 5*10 + 7*1. And, the 18 00:01:24,567 --> 00:01:33,102 so-called base of the number representation has to do with the powers 19 00:01:33,102 --> 00:01:37,884 they're involved here. And the word position comes from the fact 20 00:01:37,884 --> 00:01:43,704 that if you start counting from the, the right end, the position tells you what 21 00:01:43,704 --> 00:01:47,498 the exponent is. That's implicit in the positional 22 00:01:47,498 --> 00:01:52,042 representation. So, we know that the 7 is, is the number 23 00:01:52,042 --> 00:01:56,691 the 1's, the 5 corresponds to the number of 10's, etc. 24 00:01:56,691 --> 00:02:02,034 And so, this is called base 10, that's what decimal means is base 10. 25 00:02:02,034 --> 00:02:08,322 And you write that with this little subscript over here to tell you the base. 26 00:02:08,322 --> 00:02:16,669 Also in base 10 of every digit in each position is an integer between 0 and 9, 27 00:02:16,669 --> 00:02:22,037 and this 9 is important, it's 1 less than the base. 28 00:02:22,037 --> 00:02:28,736 So, if you add two numbers together and one of the positions adds up to being a 29 00:02:28,736 --> 00:02:33,350 number bigger than 9, you know what you do is you do a carry to 30 00:02:33,350 --> 00:02:39,734 the next position to the left and adjust the number accordingly so it fits in the 31 00:02:39,734 --> 00:02:45,025 range between 0 and 9. So, that's all we need to know about base 32 00:02:45,025 --> 00:02:48,192 10. The, I've got to point out that 33 00:02:48,192 --> 00:02:55,467 positional notations really important. A alternate representation of numbers is 34 00:02:55,467 --> 00:02:59,817 Roman numerals, and 257 happens to be this in Roman numerals. 35 00:02:59,817 --> 00:03:05,462 I think you might be hard for us to multiply this by 2, 36 00:03:05,462 --> 00:03:11,183 which I'm going to write again in Roman numerals without using positional 37 00:03:11,183 --> 00:03:14,810 notation. If you tried to stay in the Roman numeral 38 00:03:14,810 --> 00:03:20,899 world, it's very, very hard to multiply. not as hard but pretty difficult to add 39 00:03:20,899 --> 00:03:26,913 and I would not even think about dividing in Roman numerals, that's going to be a 40 00:03:26,913 --> 00:03:28,092 disaster. So, 41 00:03:28,092 --> 00:03:32,608 positional notation when it was discovered, makes all the simple 42 00:03:32,608 --> 00:03:38,463 arithmetic operations very, very easy and it's quite concise in representing very 43 00:03:38,463 --> 00:03:41,819 big numbers and that's a very useful thing. 44 00:03:41,819 --> 00:03:46,855 Well, in a computer, numbers are represented in what we call binary and 45 00:03:46,855 --> 00:03:52,580 all that is, is base 2 is still positional notation. So here, I have a 46 00:03:52,580 --> 00:03:58,662 number 10000001, and the little subscript here 2 tells me it's page 2. 47 00:03:58,662 --> 00:04:05,097 So, I know that the, the position furthest to the right represents the 1's 48 00:04:05,097 --> 00:04:12,322 position, which is 2 to the 0, the next position over represents 2^1, and the 49 00:04:12,322 --> 00:04:17,524 next position to the left from that, 2^2, etc. 50 00:04:17,524 --> 00:04:23,610 And, I know my powers of 2. So I know that this, of course is 1, 51 00:04:23,610 --> 00:04:32,794 that's 2, that's 4, 8, 16, etc. So, this number this red one corresponds 52 00:04:32,794 --> 00:04:40,348 to the 2^8 position. So, our number here in binary is 2^8+2^0 53 00:04:41,481 --> 00:04:47,008 or 1. I happen to know that 2^8 is 256. So, 54 00:04:47,008 --> 00:04:54,719 this turns out to be our old number that we've been talking about that represented 55 00:04:54,719 --> 00:04:59,652 in binary. So, everything's the same in base 2 or in 56 00:04:59,652 --> 00:05:03,794 base 10. In base 2, you, all the numbers are 57 00:05:03,794 --> 00:05:09,912 either 0 or 1 in each position because that's 1 less than the base. 58 00:05:09,912 --> 00:05:15,601 Carries work the same way it's all the same except it's in base 2. 59 00:05:15,601 --> 00:05:21,779 Like I said, it's because voltage is either being 0 or some positive voltage 60 00:05:21,779 --> 00:05:27,062 make it easy to represent numbers electricly in base 2. 61 00:05:27,062 --> 00:05:31,417 Now, here are the powers of 2, which I suggest you learn. 62 00:05:31,417 --> 00:05:36,712 It's very important to know them. I know that 2^5 is 32, for example. 63 00:05:36,712 --> 00:05:42,235 one of the more important ones, though, is the one at the bottom. 64 00:05:42,235 --> 00:05:46,891 And that is very interesting and very useful result to know. 65 00:05:46,891 --> 00:05:53,701 And that, and what that means is 2^10, it's about equal to 10^3. 66 00:05:53,701 --> 00:05:59,931 In fact, on some of the computers when they say a k, it usually means 1000, 1k 67 00:05:59,931 --> 00:06:04,820 and something. 1k on some computer systems actually 68 00:06:04,820 --> 00:06:09,691 means 1024 because it's very close to being 1,000. 69 00:06:09,691 --> 00:06:16,193 now, how do you represent numbers? And what are some of the various 70 00:06:16,193 --> 00:06:23,959 conventions for this positional notation? So, computers are often arranged in terms 71 00:06:23,959 --> 00:06:31,531 of what they call words. And here, I show a word that's 8-bits 72 00:06:31,531 --> 00:06:38,760 long, bit means binary digit. You may not know 73 00:06:38,760 --> 00:06:48,851 that but it means binary digit. And so, this word is 8-bits long here and 74 00:06:48,851 --> 00:06:56,593 turns out that it is what is known in the trade as a byte. 75 00:06:56,593 --> 00:07:06,647 And you, the most computers these days make devote many more bits to an integer 76 00:07:06,647 --> 00:07:12,259 than 8. usually though, they're multiples of 8 so you can have 64-bit. 77 00:07:12,259 --> 00:07:17,837 When we're talking about 64-bit computers, that means integers can be 78 00:07:17,837 --> 00:07:23,997 represented by 8 bytes etc. Let's talk about the simpler easy to 79 00:07:23,997 --> 00:07:29,705 manage a 8-bit manager. And notice, the word here on this is 80 00:07:29,705 --> 00:07:34,832 unsigned. So, this is exactly positional notation. 81 00:07:34,832 --> 00:07:38,933 The subscript here refers to the power of 2. 82 00:07:38,933 --> 00:07:46,710 So, in 8-bits, the powers of 2 go from 0 to 7. And that means I can represent 83 00:07:46,710 --> 00:07:54,291 numbers equal to 0 to 255, and 255 is 2^8-1 because there is no eighth 84 00:07:54,291 --> 00:07:59,052 exponent. When you turn on every one of these 85 00:07:59,052 --> 00:08:04,002 digits, you get 255 which is 1 less than 2^8. 86 00:08:05,818 --> 00:08:15,381 Now, we'd also like to be able to talk about integers with the sign. And what is 87 00:08:15,381 --> 00:08:24,702 done is they take the same 8-bits that you had before, and you you use them. 88 00:08:24,702 --> 00:08:30,758 You have to devote one bit here to the sign. And if it's a 1, that tells you 89 00:08:30,758 --> 00:08:34,824 it's negative, if it's 0, it's positive. But now, you 90 00:08:34,824 --> 00:08:41,041 only have 7 bits to represent numbers. When all is said and done that the range 91 00:08:41,041 --> 00:08:47,132 numbers that's represented by a signed 8-bit integer ranges from -128 to 127. 92 00:08:47,132 --> 00:08:52,667 And, you might wonder why there's more to the negative side than another. But it 93 00:08:52,667 --> 00:08:58,697 turns out you, in some sense, get an extra number because 0+0 is the same as 94 00:08:58,697 --> 00:09:01,791 -0. So, what is normally done is they 95 00:09:01,791 --> 00:09:07,559 allocate the extra, if you will to the negative side for all kinds of reasons 96 00:09:07,559 --> 00:09:13,169 that aren't worth getting into. Well, that's very nice. But, how about 97 00:09:13,169 --> 00:09:18,820 anything with a fraction? What are we going to do about that? And that's where 98 00:09:18,820 --> 00:09:24,891 a floating point comes in. So, in floating point, the representation 99 00:09:24,891 --> 00:09:30,114 number is m, so called mantissa, times 2^e where e is the exponent. 100 00:09:30,114 --> 00:09:36,405 So, what you do is you take a very long word, not 8-bits, much longer than that. 101 00:09:36,405 --> 00:09:41,852 You devote one part of it to the exponent, including a sign, so it's a 102 00:09:41,852 --> 00:09:46,307 signed integer. And you devote another part of the word 103 00:09:46,307 --> 00:09:51,286 to being assigned an integer, which stands at the mantissa, 104 00:09:51,286 --> 00:09:56,054 except it's not an integer. It turns out to be what we will call a 105 00:09:56,054 --> 00:10:01,099 floating point fraction. So, when you divide this up into 106 00:10:01,099 --> 00:10:04,652 individual bits, this is the 2^-1 bit, 107 00:10:04,652 --> 00:10:07,671 this one is the 2^-2 bit, etc. Okay? 108 00:10:09,080 --> 00:10:18,867 And this restriction that m has to be between the 1/2 of one means, this bit is 109 00:10:18,867 --> 00:10:27,582 the first bit is always on and the rest are whatever a number it's required to 110 00:10:27,582 --> 00:10:31,267 fill in that range. So, what happens is that you get a 111 00:10:31,267 --> 00:10:36,757 number, you scale it so the mantissa is in the right range, and that tells you 112 00:10:36,757 --> 00:10:41,352 what the exponent is. And that is written as a signed integer. 113 00:10:41,352 --> 00:10:48,849 So, a 1/32, which is 2^-5, is actually expressed in floating point as 1/2*2^-4. 114 00:10:50,166 --> 00:10:58,413 And that means there is a one in first position and zero everywhere else since 115 00:10:58,413 --> 00:11:04,617 it's exactly 1/2. And then, I represent as a signed integer 116 00:11:04,617 --> 00:11:09,285 -4. So, that's how floating point handles 117 00:11:09,285 --> 00:11:15,607 numbers that actually span in very large range, and can be negative and can be 118 00:11:15,607 --> 00:11:19,548 fractions. So, you can go from minus a very small 119 00:11:19,548 --> 00:11:25,922 fraction up to plus a very big number all in one concise representation. 120 00:11:25,922 --> 00:11:31,112 On computers these days, you can see one 64-bit floating point. 121 00:11:31,112 --> 00:11:36,717 You can actually see 128-bit floating point for some calculations. 122 00:11:36,717 --> 00:11:43,402 So, that's how numbers are represented on computers and how computations are done. 123 00:11:43,402 --> 00:11:49,800 Now I want to point out, that the numbers which we're going to relate to signal 124 00:11:49,800 --> 00:11:55,471 values are all, can be represented a variety of ways signed, unsigned, 125 00:11:55,471 --> 00:11:59,788 floating point or not, but always with discrete values. 126 00:11:59,788 --> 00:12:06,574 I want to point out a number like 1/3 is an infinte repeating decimal, it's also 127 00:12:06,574 --> 00:12:13,473 an infinite repeating fraction in binary. Since you only have a fixed number of 128 00:12:13,473 --> 00:12:20,813 bits for any wor, number on a computer, they have, can, 1/3 cannot be represented 129 00:12:20,813 --> 00:12:23,780 exactly. There's always in effect, an error in 130 00:12:23,780 --> 00:12:27,668 representing a number. So, we're going to have to learn how to 131 00:12:27,668 --> 00:12:33,244 live with discrete amplitude values represented by different numbers in a 132 00:12:33,244 --> 00:12:38,661 computer. And this also means, by the way, that the computations are also not 133 00:12:38,661 --> 00:12:42,272 quite exact. It depends on what the numbers are. 134 00:12:42,272 --> 00:12:48,444 Furthermore, numbers are always stored in individual memory locations. So, that may 135 00:12:48,444 --> 00:12:54,117 seem like a minor point, but that means we cannot store a continuum of values. 136 00:12:54,117 --> 00:12:59,116 So, we've been talking about analog signals, which are functions of 137 00:12:59,116 --> 00:13:04,435 continuous time and usually have a continuous range of values. 138 00:13:04,435 --> 00:13:10,213 So, storing an individual memory locations mean we have to store just a 139 00:13:10,213 --> 00:13:15,255 few values of our signal. We can't store them all because the 140 00:13:15,255 --> 00:13:21,314 number of values in any interval in continuous time is uncountably infinite, 141 00:13:21,314 --> 00:13:25,440 that's a very big number. Furthermore, the amplitude values cannot 142 00:13:25,440 --> 00:13:30,117 be made exactly because there's some numbers we cannot represent exactly. 143 00:13:30,117 --> 00:13:34,819 But also, even beyond that, we can't represent all possible numbers, let's say 144 00:13:34,819 --> 00:13:37,127 between -1 and 1. That's impossible. 145 00:13:37,127 --> 00:13:41,897 So, we're going to have to learn about quantization and time, and quantization 146 00:13:41,897 --> 00:13:45,232 and amplitude. And that's going to be the subject of our 147 00:13:45,232 --> 00:13:45,882 next video.