In this lecture, we'll look at the data types that we commonly use to represent integers in our C-Sharp code. What is an integer? An integer is a number without a decimal or fractional part, like 0, or 42, or a negative 11. The foremost commonly used integer data types in C-Sharp are byte, short, int, and long. What's the difference between them? The difference is the number of bits that we use to represent each of those data types. A byte is represented in memory with eight bits, and a short uses 16-bit, and an int uses 32 bits, and a long uses 64-bit. What does that tell us? Well, we know that two to the b equal n, so we know that if b is smaller then n is smaller. A byte can only store 256 unique values from 0-255, and then as we move through short, int, and long, we get a wider range of values that we can represent in that particular datatype. The Operations for our integer data types in C-Sharp are pretty much what you would expect except for division. Think back to your grammar school or grade school days when you learned how to do division, and when you did division you came up with a quotient and a remainder. Well, the division operator on integer datatypes in C-Sharp gives us the quotient and we'll explore that some more once we start coding with integers. Let's start coding with integers. I've started up Visual Studio and I'm going to create a new project and we're building a console app here. I've got console app here on the left, so I'll say next, and I will call it IntegerDataTypes, and I'm just saving it in the default location, so I'll say next. Remember we start our console apps with.NET 5.0 so that we get the full mean method, not that abbreviated stuff if we pick.NET 6.0. I'll create and I'm going to comment the program integer data types lecture code. I'll comment the main method as well, three slashes, and I'll say demonstrates integer datatypes and I'll add a comment here that says these are the command line args or command line arguments. We won't use command line arguments in any of the courses in the specialization, but they can be useful with console apps, especially if you do batch processing of assets for your games. But we won't cover that topic in the courses here. We don't want to say Hello world, instead we're going to declare a variable, which we'll get to soon, and then I'm going to say, calculate minutes and seconds played. We're going to start with the total seconds played for a game, and then we're going to calculate how many whole minutes set is and how many whole second set is, and then we'll print those out as well. As I said, I'll start by declaring a variable and we start with the datatype and because the total seconds played will be a whole number, I'm going to use int as my datatype. Now I give my variable a name, a name for that location in memory, and I'll call it total seconds played. Now, you'll notice that I started my variable name with a lowercase character, and then each word in the middle of the variable name starts with a capital letter, this is not required by C-Sharp, but it is standard C-Sharp programming practice. The compiler won't complain if you mix the case all over the place like you might for your passwords and so on, but this is the best way to write your C-Sharp code so that others C-sharp programmers can just glance at a name and know that it's a variable. This style of capitalization actually has a name, It's called camel case, because here's the head of the camel and then there are some humps on the camel. I didn't make that up, but that's what it's called camel case. This is a valid variable declaration, but I actually want to give my variable an initial value as well. I'm going to set it to 100. I have total seconds played is a 100. Now we'll calculate the minutes played, and that will be another whole number, so another int. You'll notice that the IntelliSense is trying to help me to guess at what I want it to be, but it's guessing wrong, so I'm just going to keep typing. Minutes played. Is equal to, and again, I don't want it to be 0, I want it to be total seconds played and this one I'll take so Tab. Actually I do want to divide by 60. So I'm going to hit "Tab" again. That's a good line of code that will use that integer division we talked about to calculate the total seconds played and that gives us the quotient of that division. Now, I want to print minutes played. You might think I should just keep on typing and to type everything in and then try it. But that's not a good idea for developing our software, whether it's for games or just software in general. We should add a little bit and test it, and add a little bit and test it. I'm modeling that behavior for you because that's the right way to do it. We know how to print stuff out in console apps. We use console dot write line, I'll tab to accept the right line. Here in the code I'm demonstrating to you, I'm going to label my output so that the user knows what we're printing out. In the programming assignments you do in the courses in this specialization, you won't be labeling output because many people would come up with a variety of different labels for their output and really as I compare your actual results to the expected results for each assignment, I just want to make sure you've got the numbers right. It would be really hard to make sure everyone got reasonable labels, but they're not all the same. Even though we're labeling our output here in the lectures, you won't be labeling the output in the auto graded programming assignments you do in the courses. I have a label, but I don't actually have minutes played. I'll say plus minutes played. Of course, I want to semicolon at the end of that line. Here's how this code works. We know about Console.WriteLine. We've actually printed out string literals before. This will get printed out literally the way you have it, because it's between double quotes. Because this is a string. Minutes played, which we know is an integer will actually get converted to a string. Now we want to join these two strings together and we do that with plus. This isn't actually mathematical addition. This is called concatenation when we join two strings together. I'll run the code with Control F5. As you can see, minutes played is 1, which is exactly what we expected. Now I want to calculate seconds played. Another integer. Look that's trying to help me, so I'll take some of this. Except I know it's not an integer division. I know I need to do something to get the remainder, not the quotient. I also know though, when I do that something and I'll tell you that something now that's the percent sign. That gives us the remainder in integer math. But I don't want to type 60 again. This is the second time I'm typing 60 and 60 isn't just some generic number, it actually has semantic meaning. This 60 here means how many seconds per minute. This is actually called a magic number because somebody who's reading your code later has to magically know that 60 means seconds per minute. Let's actually declare a constant that will actually make it much clearer in the code what that 60 minutes. When we're declaring a constant. We say const and then we provide the datatype int and now I want seconds per minute. And I'll set it equal to 60. Now you'll notice for constants, I start the constant name with a capital letter and I do the same thing with each word in the constant name. But it starts with a capital letter, not a lowercase letter. Again, that's not required by the C-Sharp language, but it is good C-Sharp programming practice. This capitalization scheme also has a name, and it's called Pascal case because that's how we use to name things in the ancient but a great teaching language, Pascal. Now if we come down here and replace those 60s with seconds per minute, it makes our code much more readable for us to understand. Now, this is pretty straightforward. Somebody could probably figure out that because of the math we're doing the 60 means seconds per minute. But as you build more interesting games or aborted interesting code, you might have the number 10 for what damage a particular weapon does. You might also have a 10 for how many seconds the cool down is for after you fired your weapon. Somebody would have to magically know which 10s meant weapon damage, and which 10s meant, cool-down time. Using constant really helps to get rid of those magic numbers and make our code more readable. Now we'll print out the seconds played as well. I'll print out the value of the variable that we just calculated and when I control F5 you can see we played one minute and 40 seconds, if we played for 100 seconds. You should be able to convince yourself that is the correct math for playing 100 seconds. Last comment before we leave Visual Studio, I will say that if you go to the Internet and look up how to declare a variable, you'll find lots of people saying, you don't have to put int, you can just put var. That's true, that's valid C#. I'm not trying to be offensive but let me tell you, if you're using var as you're trying to learn how to program, it's because you're too lazy to try to figure out the actual data type you want to use. At least in an introductory set of courses, I want you to actually think about, what datatype each variable should be. You can certainly get away with saying var in C#, but I'd really prefer you to explicitly figure out the data types you need when you're declaring your variables. Let's see how well you can do integer math. Look at this slide and pause the video and come up with your answer and then unpause the video. Well the answer is 1 plus 1 is 2. Isn't this awesome? You're taking a college level class and you're able to do 1 plus 1 and hopefully you got 2. This is great. You can do college math. This next one is a little more challenging so go ahead and look at this question, pause the video come up with your answer and then unpause the video when you're ready. The answer to this one is probably counter-intuitive to you, because the number we start with is the maximum possible integer we can represent with 32-bit. When we add one to it we get the minimum or the smallest negative number we can represent with 32-bit. I've provided in additional reading for you in the lecture resources so you can understand if you wrote, why this actually happened, but we wrap around from the biggest possible number to the smallest negative number. Just in case you think well, that's great. You're a geeky professor and that's of academic interest but who cares. Well it turns out that rock star cares because in the initial release of Grand Theft Auto V they ran to this exact problem. A player got very rich and then they earned a little more money and they were very bankrupt. It was because 2^b equal n and that integral number wrapped around. This is not just of academic interest it actually really matters for game development. Before we end this lecture I want to talk a little bit about the difference between value types and reference types. Value types, the bits that are stored in the memory location are interpreted as a particular value. For this particular lecture, those bits are interpreted as some whole number, it might be a byte, short, int or long but a whole number. When we get to the next module when we talk about classes and objects, we'll talk about something called reference types. Where the bits in the memory location for a particular variable are actually interpreted as a reference to an object somewhere else in memory. We don't really need to worry about that until we get to classes and objects, but because this was my first opportunity to talk about value types versus reference types, I wanted to take advantage of that here. To recap, we learned about the commonly used data types that we can use to represent whole numbers in our C# code and I will say that we will pretty typically just use int as our whole number data type. Although there are other times that we might opt to use those other data types. In general we'll use interferon game development. We also learned that one of the limitations of 2^b equal n is that, integers will wrap around from either the lowest negative to the highest positive or the highest positive to the lowest negative if we reach the biggest number we can represent with a particular sign.