Subtitles section Play video Print subtitles >> [MUSIC PLAYING] [MUSIC - ROSSINI, "RANZ DES VACHES" FROM WILLIAM TELL] >> [MUSIC - THE ENGLISH BEAT, "MARCH OF THE SWIVEL HEADS"] >> [APPLAUSE AND CHEERING] >> DAVID MALAN: So this is CS50. My name is David Malan. And 73% of you have no prior experience with computer science, contrary to what you might think. So today we thought we would chip away at that lack of familiarity, but also give you a sense of, for those of you with more comfort, which directions you can go this semester. >> So let's start with this. I really have no idea what's inside of a computer, even though, like you, I use it every day. But it's some kind of box, and there's not many inputs into it. Minimally, there's, what? Probably a power cord. >> And indeed with this one ingredient, electricity, we seem to be capable of doing quite a bit these days. But at the end of the day, we have to represent the things that we care about. We have to represent information in some form. And you're probably at least vaguely familiar with the idea by binary or bits somehow or other, computers reduced to zeros and ones. But can we embrace that and at least put a bit of light to that? >> So I have these little desk lamps here. I have an electrical outlet here. And I'm going to propose that inside of my computer is at least one of these things, something capable of being switched on or off. In this case, it's indeed a desk lamp, but at the lower level, it's something called a transistor. >> But in our world, it's a desk lamp, so I'm going to go ahead and plug this into my electricity here. And I claim that using this simple, simple device, this simple switch, I can represent information. For instance, right now, I am representing nothing, right? I'm representing what I'll call 0 or false, the opposite of something actually being present. But if I simply turn this switch, now I've represented a 1. So using this very simple piece of memory, if you will, I can represent information. >> Now unfortunately, my computer can't do all that much. It can only represent two values in the whole world-- 0 or 1. But what's an obvious solution, now, if we want to expand our computer's memory and represent more than just 0 and 1? >> Well, let's grab another such bit. Let's grab another switch, another transistor, however you'd like to think about it. Let me go ahead and plug this into my computer as well. And I'm going to claim, now, that by using a bit more electricity and turning more of these switches on and off, I can represent more such information. >> So right now, this is 1. If I want to now represent 2, I could do this. But typically, convention, as we'll eventually see, will have me do this. So this is 0, this is 1. This would be 2. And not surprisingly, this would be 3. >> So in this way, still, can we count up even further? If I get a third bit, a third switch, what's the highest number I can now count up to from 0? So 7 if I'm starting at 0, right? Because if I turn this light on and actually plug this third and final light into my electrical socket here, then I have the ability to represent any of two values here, two values here, two values here-- and so I can represent 2 times 2 times 2, or eight possible values. And if I start accounting at 0, so that's 0, 1, 2, 3, 4, 5, 6, 7. >> So this binary. It really is as simple as that. And I'd argue that this is actually quite familiar to most everyone in this room. Let me go ahead and open a little text editor here. >> And you might recall from grade school that we had things like the hundreds place, the tens place, and the ones place. And recall that if you had some decimal number, like something random like 123, you would essentially write that out in the form of these three columns. And why is 1, 2, 3 what we know as 123? Well, in the leftmost column, we have one 100 plus two 10s, so that's 120, plus three 1s, so that's 123. >> Now this world that we just illuminated is exactly the same as you've been familiar with for years, except now, our columns aren't powers of 10. They're just powers of 2. So whereas that's the ones place, this is going to be the twos place, this is going to be the fours place. >> And because I am only using the simplest of mechanisms to turn things on and off-- electricity is flowing or electricity is not flowing-- I don't quite have the same expressive range as 0 through nine. We're going to keep it super simple in this world of computers. I only have 0 or 1-- off or on, false or true. >> And so what I'm representing right now is 1, 1, 1, because each of these lights is illuminated. Well, that gives me one 4 plus one 2, so that's 6, plus one 1, and that's 7. And ergo does this sequence of three bits represent the number 7. >> So all this time, inside of your computer, have been any number of transistors, any number of bits. But at the end of the day, we can represent information as simply as that. Now unfortunately, we've only counted up to 7 in CS50 thus far, but hopefully we can do a bit better than that. And indeed we can. >> Suppose that we as humans just arbitrarily decided that we are going to associate numbers like 1 and 2, 3, 4, 5, 6, 7, with specific letters of the alphabet. And for historical reasons, I'm going to start somewhat arbitrarily, but I'm going to say, humans, we are going to decide as a standard, globally, that 65 represents the number the letter A. 66 will represent B. Dot, dot, dot. 90 will represent the letter Z. >> And let's suppose, if we really put some thought into it, we could come up with numbers for exclamation points and lowercase letters, and indeed, other people have done that for us. So now we had bits with which we can represent numbers, numbers with which we can represent letters, and with letters can we now start composing emails and printing characters on the screen. >> So let me invite, if I could, eight brave volunteers-- who don't mind appearing not only on camera but on the internet-- to come up here and represent eight such bits, rather than these three. So how about one, two? How about three? How about four in light blue, five on the end? About someone over here? Six in front, seven in front, and eight in front, as well. >> So I just so happened to come prepared with a whole bunch of slips of paper. And on these pieces of paper are numbers that represent what columns you guys are going to represent. So you will be-- what's your name? >> STUDENT: Anna Leah. >> DAVID MALAN: Anna Leah, you will be the 128s column. You are? >> STUDENT: Chris. >> DAVID MALAN: Chris will be the 64s column. You are? >> STUDENT: Dan. >> DAVID MALAN: Dan will be the 32s column. >> STUDENT: Pramit. >> DAVID MALAN: Pramit will be the 16s column. >> STUDENT: Lillian. >> DAVID MALAN: Lillian will be the 8s. >> STUDENT: Jill. >> DAVID MALAN: Jill will be the 4s column. >> STUDENT: Mary. >> DAVID MALAN: Mary will be the 2s, and? >> STUDENT: David. >> DAVID MALAN: David will be the 1s column. So if you guys could step a little forward so that everyone can see. What you guys don't see is that on the back of these slips of paper is a little cheat sheet that's about to instruct these eight bits to either raise their hand or not raise their hand. If their hand goes up, they're representing a 1. If their hand stays down, they're representing a 0. >> Meanwhile, we the audience should be able to figure out, based on this mapping, what three-letter word these folks are about to spell out. So in just a moment, you're going to read the first line off the back of your cheat sheet, and you're either going to raise or not raise your hand. If you're a 1, you raise, if you're a 0, you stand there awkwardly, just like that. Go. What number, first and foremost, are these guys representing? >> 66. 66, right? We have a 1 in the 64s column, a 1 in the 2s column. That gives me 66, so that appears to be representing B. So you guys have spelled-- OK, that's enough. B. >> So now let's move onto our second letter. Go. Who's quickest at math here? So 79.