1 00:00:00,000 --> 00:00:00,400 2 00:00:00,400 --> 00:00:02,720 >> SPEAKER: Recall that everything underneath the hood of a computer is 3 00:00:02,720 --> 00:00:03,900 stored using bits. 4 00:00:03,900 --> 00:00:06,320 And bits, in turn, can be used to represent numbers. 5 00:00:06,320 --> 00:00:09,020 And numbers, in turn, can be used to represent characters. 6 00:00:09,020 --> 00:00:12,530 In fact, there exists a conventional mapping between those numbers and 7 00:00:12,530 --> 00:00:14,260 letters, called ASCII-- 8 00:00:14,260 --> 00:00:17,130 American Standard Code for Information Interchange. 9 00:00:17,130 --> 00:00:20,460 >> Now with C, it turns out that we can see this equivalence, because we not 10 00:00:20,460 --> 00:00:24,400 only have ints, we also have chars, both of which at the end of the day 11 00:00:24,400 --> 00:00:27,240 are represented as numbers and, in turn, bits. 12 00:00:27,240 --> 00:00:30,850 So let's write a simple program that simply tells me what the mapping is 13 00:00:30,850 --> 00:00:37,650 between numbers and letters, keeping in mind that 65 is a capital A and 97 14 00:00:37,650 --> 00:00:39,080 is a lower case a. 15 00:00:39,080 --> 00:00:40,630 Let's begin. 16 00:00:40,630 --> 00:00:49,680 >> "include standard I/O dot h." "int main void." And now I'd like to 17 00:00:49,680 --> 00:00:53,380 iterate over all of the capital letters printing out their numeric and 18 00:00:53,380 --> 00:00:54,680 character equivalents. 19 00:00:54,680 --> 00:00:56,960 So for this, I'll use a "for" loop. 20 00:00:56,960 --> 00:00:59,560 "for int i gets-- 21 00:00:59,560 --> 00:01:03,120 and now, rather than start at the usual 0, why don't I start at a value 22 00:01:03,120 --> 00:01:07,130 I know to be significant, like 65 for capital A? 23 00:01:07,130 --> 00:01:10,300 Let's do this, so long is i is less than-- 24 00:01:10,300 --> 00:01:10,600 um-- 25 00:01:10,600 --> 00:01:17,190 65 plus 26, because I know there are 26 letters in the alphabet. 26 00:01:17,190 --> 00:01:20,840 And then on each iteration of this loop, let me increment i by 1. 27 00:01:20,840 --> 00:01:23,640 >> Now, on each iteration of this loop, what do I want to do? 28 00:01:23,640 --> 00:01:27,390 I'd like to print out what the current number is i and what the 29 00:01:27,390 --> 00:01:29,570 corresponding char is. 30 00:01:29,570 --> 00:01:34,920 Now, to achieve that, I can cast, so to speak, the int to a char in the 31 00:01:34,920 --> 00:01:37,800 following way. 32 00:01:37,800 --> 00:01:45,830 "print f %i is %c backslash n" In other words, I want to say, this 33 00:01:45,830 --> 00:01:48,350 number is this character. 34 00:01:48,350 --> 00:01:51,940 So I need to plug in two values to this place holders for print f, so 35 00:01:51,940 --> 00:01:55,130 I'll do comma i, comma-- 36 00:01:55,130 --> 00:01:58,400 >> Now, I don't have a variable c or a char, but I do have a number. 37 00:01:58,400 --> 00:02:01,940 And I know that numbers can be mapped to letters, I simply need to tell the 38 00:02:01,940 --> 00:02:03,230 computer to do that. 39 00:02:03,230 --> 00:02:09,020 And so I can cast i from an int to a char, simply by specifying in 40 00:02:09,020 --> 00:02:12,850 parentheses that I'd indeed like to convert it to a char. 41 00:02:12,850 --> 00:02:17,440 >> Let's close now this statement, save the file, and compile this program. 42 00:02:17,440 --> 00:02:23,590 "make ascii 0 dot slash ascii 0." And very quickly print it to the screen as 43 00:02:23,590 --> 00:02:26,760 this mapping between numbers and their character equivalents. 44 00:02:26,760 --> 00:02:31,920 In fact, if I scroll back up, I first see that 65 is A, 66 is B, and if I 45 00:02:31,920 --> 00:02:35,520 scroll back down, 90 is Z. 46 00:02:35,520 --> 00:02:35,597