1 00:00:00,390 --> 00:00:04,530 So far, we've encountered one type of variable, which is a string. 2 00:00:05,280 --> 00:00:08,030 Now there's an important word in there and that's called type. 3 00:00:08,550 --> 00:00:13,560 When you hear people talk about programming languages, you say loosely typed, strongly typed. 4 00:00:13,770 --> 00:00:15,270 In some cases, no types. 5 00:00:15,930 --> 00:00:21,200 What they're referring to is the kind of thing that's stored in memory as a variable. 6 00:00:21,600 --> 00:00:26,880 So to give you a counterexample to the string that we had before it, you can kind of see the remnants 7 00:00:26,880 --> 00:00:27,280 of here. 8 00:00:27,300 --> 00:00:28,200 Hello, playground. 9 00:00:28,590 --> 00:00:35,220 What we're going to do is have a variable number, which is like equal to number eight or something. 10 00:00:36,340 --> 00:00:36,730 Right. 11 00:00:37,180 --> 00:00:40,060 So what is that number type? 12 00:00:40,090 --> 00:00:43,000 Well, it's not a string because it doesn't have the quotes around it. 13 00:00:43,600 --> 00:00:48,040 It's actually an integer, which is a whole number in everyday language. 14 00:00:48,400 --> 00:00:53,500 Now, there are some nuances to integers that you need to be aware of, but we'll get into those as 15 00:00:53,500 --> 00:00:54,720 we move on with the course. 16 00:00:55,180 --> 00:00:58,450 Let's have a var numb to. 17 00:01:00,260 --> 00:01:03,980 Equal to and let's give this a decimal seven point eight. 18 00:01:05,660 --> 00:01:06,890 What kind of number is that? 19 00:01:07,010 --> 00:01:09,140 Well, it's not an integer because it's not a whole number. 20 00:01:09,560 --> 00:01:15,350 This is actually a double, which stores a very long sequence of numbers, depending on the processor 21 00:01:15,360 --> 00:01:17,830 you have in your system, 32 bit or 64 bit. 22 00:01:18,440 --> 00:01:22,220 But basically it's there to do the complex number calculations. 23 00:01:22,570 --> 00:01:22,910 Okay. 24 00:01:23,090 --> 00:01:25,280 And I don't mean complex number in the math sense. 25 00:01:25,280 --> 00:01:30,160 I mean long numbers to basically what else are we going to have here? 26 00:01:30,170 --> 00:01:36,110 Let's have our number three and let's explicitly call this something. 27 00:01:37,100 --> 00:01:44,930 Which is a float now, this is the same thing as a double, we can store decimals in it, but but it 28 00:01:44,930 --> 00:01:48,770 has a much shorter range so we can store fewer decimals. 29 00:01:49,100 --> 00:01:54,410 Now, if I was writing a finance app to do High-Speed Trading on the stock market, I would never use 30 00:01:54,410 --> 00:01:54,860 a float. 31 00:01:54,860 --> 00:02:00,770 I would use the most accurate number because the rounding errors that come from floats will destroy 32 00:02:00,770 --> 00:02:05,330 your application and give you totally incorrect output rates. 33 00:02:05,360 --> 00:02:07,320 That would be an error, obviously. 34 00:02:07,880 --> 00:02:14,150 Now, if you want to know what type of things these are, we can actually call something that's called 35 00:02:14,300 --> 00:02:14,750 type. 36 00:02:15,230 --> 00:02:17,180 Here it is on the second line type of. 37 00:02:17,510 --> 00:02:19,310 And if you just pass in. 38 00:02:20,310 --> 00:02:23,160 Let's say numb, and then we run all of this. 39 00:02:24,620 --> 00:02:26,990 You're going to see this is the integer type. 40 00:02:28,430 --> 00:02:28,740 Right. 41 00:02:29,060 --> 00:02:32,450 And of course, we can do the same with number two. 42 00:02:34,480 --> 00:02:36,160 And the same with number three. 43 00:02:41,230 --> 00:02:47,050 OK, so we have an inch, we have a double and we have a float, so we can always check the types. 44 00:02:47,620 --> 00:02:53,420 Of course, like I said before, sometimes it's better to make it explicit what you want. 45 00:02:53,710 --> 00:03:00,940 So if I was making a financial map, everything would be a double in the highest, what you call it 46 00:03:01,750 --> 00:03:02,430 certainty. 47 00:03:02,440 --> 00:03:03,640 That's not the word I'm looking for. 48 00:03:03,670 --> 00:03:04,090 What's the word? 49 00:03:04,090 --> 00:03:04,950 I'm looking for people. 50 00:03:05,530 --> 00:03:06,610 The highest accuracy. 51 00:03:06,640 --> 00:03:07,030 That's it. 52 00:03:07,330 --> 00:03:11,190 Highest accuracy type of number. 53 00:03:11,830 --> 00:03:12,130 Right. 54 00:03:12,150 --> 00:03:13,390 So what's next? 55 00:03:14,370 --> 00:03:15,970 Ah, here we go. 56 00:03:17,560 --> 00:03:24,790 Now in iOS and Mac in general, every integer is actually referred to as a unit, which I think stands 57 00:03:24,790 --> 00:03:25,850 for Universal Integer. 58 00:03:26,050 --> 00:03:27,100 I could be wrong about that. 59 00:03:28,260 --> 00:03:36,270 If we take a ONT eight that is actually stored in eight bytes, I believe, or eight bits, one of the 60 00:03:36,270 --> 00:03:39,630 other, and if we look at the Macs and then press play on that. 61 00:03:41,170 --> 00:03:50,720 The UNT max is two five five, so that can store from zero to two, five four or two, five five I believe. 62 00:03:51,070 --> 00:03:52,300 I think it's two five five. 63 00:03:53,290 --> 00:03:57,970 If you put a negative sign in front of it when you declare it, then you can store from like minus one 64 00:03:57,970 --> 00:03:59,800 to seven to plus one to seven. 65 00:04:00,010 --> 00:04:03,130 It's a bit of a weird one we will never use under eight. 66 00:04:03,650 --> 00:04:06,790 OK, there is no need to do it in a modern application. 67 00:04:07,570 --> 00:04:13,330 If you're making stuff on a microcontroller like an Arduino, then a untracked is your friend because 68 00:04:13,330 --> 00:04:15,530 it uses much less memory. 69 00:04:15,760 --> 00:04:19,800 Just make sure that you're never going to exceed the two five five four what you need it for. 70 00:04:20,440 --> 00:04:25,810 Now, you can imagine there are all kinds of us, such as 16 dot Macs. 71 00:04:26,140 --> 00:04:35,980 We have the U.S., 32 dot max and of course ont 64 dot Macs. 72 00:04:35,980 --> 00:04:39,410 And if we play all of these, we'll see what their maximum values are. 73 00:04:39,670 --> 00:04:41,500 So sixteen is sixty five thousand. 74 00:04:42,130 --> 00:04:46,570 You may remember that if you had really old computers and if you're young and watching this, you won't 75 00:04:46,570 --> 00:04:47,800 know this at all. 76 00:04:47,810 --> 00:04:54,430 I'm guessing we used to have screens with sixteen bit color, which was amazing because you could have 77 00:04:54,430 --> 00:04:56,860 65000 colors these days. 78 00:04:56,860 --> 00:04:58,210 You can have millions of colors. 79 00:04:58,450 --> 00:04:58,840 Right. 80 00:04:59,380 --> 00:05:00,790 But that's the state of the art. 81 00:05:00,790 --> 00:05:01,290 Back then. 82 00:05:02,530 --> 00:05:06,670 We also before that had eight bit screens which had 255 colors. 83 00:05:06,940 --> 00:05:08,740 So, you know, there's really old graphics, you see. 84 00:05:08,920 --> 00:05:10,360 Well, that's the root of it. 85 00:05:10,480 --> 00:05:13,690 It's stored an integer that was eight bits or bytes. 86 00:05:15,250 --> 00:05:17,650 It's probably bits, but anyway. 87 00:05:19,050 --> 00:05:23,920 32 bit stores that many numbers and 64 bit stores that many. 88 00:05:24,240 --> 00:05:30,300 So if I was making a financial map, I would make sure I was running on a 64 bit system. 89 00:05:30,730 --> 00:05:34,530 Every system these days is capable of 64 bit, but. 90 00:05:35,760 --> 00:05:41,370 If you run on a 32 bit, that could potentially be a rounding error for a you integer or the bit where 91 00:05:41,370 --> 00:05:44,400 it falls off the end and your whole program crashes. 92 00:05:45,340 --> 00:05:51,100 OK, so you always got to bear in mind with variables, there are limits to what they can store, what 93 00:05:51,100 --> 00:05:54,940 they can do and various other properties that they have. 94 00:05:56,090 --> 00:06:00,680 OK, now, of course, we can define integers the explicit way. 95 00:06:01,310 --> 00:06:05,420 So if I was going to do my num up top, I could say, hey, let's make this a U. 96 00:06:05,420 --> 00:06:08,710 Int eight, because it actually fits in that. 97 00:06:09,260 --> 00:06:13,130 But if I changed that to eight hundred, look what happens. 98 00:06:13,940 --> 00:06:16,130 Integer, literal, eight hundred overflows. 99 00:06:16,670 --> 00:06:21,660 So you've come to the very first error that you need to know about, which is called an overflow error. 100 00:06:22,460 --> 00:06:28,520 It basically means you've gone out of range of what can actually be stored inside that variable. 101 00:06:29,240 --> 00:06:31,340 You've heard of the website Stack Overflow. 102 00:06:32,000 --> 00:06:37,490 That's based on two errors, the stack trace where you can trace through what went wrong and the overflow 103 00:06:37,700 --> 00:06:38,690 which you've just seen. 104 00:06:39,020 --> 00:06:40,710 Hence the name stack overflow. 105 00:06:41,510 --> 00:06:41,860 Right. 106 00:06:41,870 --> 00:06:45,710 Let's give you a little bit of homework, so let's copy this over. 107 00:06:47,620 --> 00:06:49,320 And let's paste it straight in here. 108 00:06:51,970 --> 00:07:00,970 Create an integer of any value in two ways, one explicitly typed and one implicitly typed. 109 00:07:01,450 --> 00:07:01,930 Good luck.