Hey there, Gamers and Game Makers!
In this week's blog, we're going to look at a simple way you can read binary and easily convert it to English text. So, if you don't know much about binary then you probably just know it as a series of 0s and 1s and you'd be right. Binary is simply made up of 0s and 1s but the number of digits and their order is very important. You may see a long series of binary numbers with hundreds of 0s and 1s but we can actually break these down into simple chunks to work them out. Binary is simply a series of bits. Each bit being represented by a 1 or a 0. However, every eight bits make up a byte. So we start by separating our long series of binary bits into segments of eight bits. Lets look at the binary here: 010001000110111101100111. We can simplify this by breaking it up into its bytes. That looks as follows: 01000100 01101111 01100111. So, we have three bytes here. Let's look at the first byte, 01000100. The first thing to note is that the first three bits of a byte determine if the text value is upper case or lower case. 010 means upper case while 011 means lower case. So we can see that our first byte is an upper case letter, 01000100. After that, the remaining bits starting from left to right have a numerical value of 128, 64, 32, 16, 8, 4, 2, 1. If a bit is set to one, we add the numerical value associated with it to the numerical value associated with any of the other bits set to one, excluding the first three bits which remember determine if our text value is upper case or lower case. So as you can see the only bit set to one is the bit with an associated value of 4. Now if we check what the fourth letter of the alphabet is, we see it's the letter "d" and in this case we know it's an upper case "D". If you go ahead and do the same for the other two bytes we have you'll see that they are both lower case letters and we find they are "o" and "g", thus spelling out the word dog. So, simple as that, you can now read binary. Give it a try for yourself. Until next time! Hey there, Gamers and Game Makers! In this week's blog, we're going to take a look at some of the books I've been reading as of late! 1. Gwendy's Button BoxGwendy's Button Box is a novella written by Stephen King and Richard Chizmar. The book takes inspiration from one of Kings most iconic locations, Castle Rock. The book provides a great mix of suspense, fear and a look at how easily we change over time, even if we don't want to admit it. 2. ElevationElevation by Stephen King was quite an interesting read. While it's not exactly a scary read,it is a very strange tale. It's one that grips you and you can't stop reading out of pure fascination. 3. Brief Answers To The Big QuestionsBrief Answers To The Big Questions by Stephen Hawking is a fantastic read. It takes on some of the most complex questions we have with not just a knowledgeable perspective but also a very compassionate one. It gives great insight in to where we came from and where we are going but, also warns of the dangers we face in order to get there.
Until next time! Hey there, Gamers and Game Makers! in this week's blog, we're going to continue our introduction to C# in visual studio by looking at loops. Specifically a for loop and a while loop. Loops are used when we want to repeat a sequence of code several times over as long as a particular condition is met. The first loop we'll be looking at is the for loop. The for loop is used when we know the sequence is to be executed a certain number of times. For example, we might only want it to run as long as an index is below a certain value. A for loop starts off with the keyword for followed by the condition. With for loops we tend to have an index variable that keeps count of the iterations through the loop along with what's called an exit condition. The exit condition is what the index is compared too. If we did not have an exit condition, the loop would never end. The following for loop iterates through the loop as long as the index is less than the count variable. It writes out the current index step each time. Once we reach the exit condition, the loop ends. A while loop can work in a very similar way. However there are a few very important differences. As you can see, I've initialized my index variable outside the loop and the increment of the index is handled after each execution of the code. Same as before, if we don't have an exit condition, the loop would never end. Try coming up with your own loops and see what results you get.
Until next time! Hey there, Gamers and game Makers! In this week's blog post, we will continue our introduction to C# in Visual Studio series by looking at if statements. We use if statements when we want to check if certain conditions have been met before executing a particular body of code. For this example, we're going to create a console app that asks the user to input their age. If they are over 18, we tell them so. If they are under 18, we will tell them something to that effect. As you can probably guess based on the first tutorial on variables, we are going to need an int variable to store the age. We'll create an int variable called age but we wont assign it any value at this time. We will then use a Console.ReadLine() to assign the users input from the keyboard to be the value of age. We can now write our If Statement. An if statement consists simply of writing if followed by the conditional expression you are checking in brackets. This is then followed by the code you wish to execute if the condition is met in curly brackets. In this example we are checking if the age value is greater or equal to 18, we will display to the screen a message saying you are old enough to enter. With if statements we can also have else ifs that will check another condition should the first one fail. You can do as many of these as you wish but one would urge not overdoing it as it can create messy code. I have a single else if that checks if the age value is less than 18 should the first if fail to find the value to be above 18. if it is below 18, we display a message to the screen saying you are old enough to enter. We can also have else statements. These do not check a condition but rather execute a body of code should all previous ifs fail. This can be useful should the user enter an incorrect value and we need to notify them of such. Our program looks as follows. If statements can be used to check conditional expressions on strings, bools and more. The logic is the same. We can also use the "or" operator, || and the "And" operator, && to check multiple conditions at once before executing a body of code. With the && operator, both conditions must be met in order for the code to execute. However, with the || operator, only one of the conditions has to be true. For example. In the next tutorial in this series, we'll be looking at how to use loops.
Until next time! Hey there, Gamers and Game makers! Welcome to a new tutorial series, An Introduction to C# in Visual Studio. In this weeks tutorial, we're going to be looking at what variables are in C#. The various types and how to use them. So, let's get started! First thing you'll need is to have Visual Studio installed with the C# language package installed along side it. Once you have done so, click New, then New Project and select Console App. For the purpose we'll be using a console application rather than a desktop application for ease of the tutorial. Go ahead and call the project whatever you like. You'll be presented with the a basic hello world program. Don't worry about what you see for now. We'll be only looking at variables for this tutorial. So, what exactly is a variable. You can think of a variable as a container for information and different types of variables hold different types of information. A variable will reserve space in memory for whatever type of information it's to store once it has been created, or declared, to use the proper terminology. What types of variables are there? The five most common ones you'll deal with are int, float,bool, string and char. The int and float variables represent numbers. An int variable deals with whole numbers only while a float can handle decimal numbers. A bool is a variable that stores a true or false value and a string is simply a string of text. The char variable stores a single alphabet character. Let's look at some examples. Starting with how to declare an int variable. I start by declaring the type of variable by typing the word "int" followed by a name for the variable.Since an int is used for whole numbers, I'm going to call this variable "num1". I then assign a value to the variable by using the "=" sign followed by the value I wish to assign which in this case is "2". I then end the declaration with a semicolon. It's very important you do this as you'll get an error otherwise. This is all well and good but what can we do with int variables? Let's say we have more than one int variable. We can use basic mathematical operations on them in order to say, return the sum of those int variable. Let's try doing just that. I already have one int variable, so, I'm going to create a second int variable called "num2" with a value of "4" and also create an int variable called "sum" that will store the sum of my other two int variables. As you can see, we have a variable that will store the sum of our two numbers, but, how do we actually get the sum of those two numbers and assign it to the sum variable? It's nearly as you would expect to do it on paper, we add the two variables using an addition sign. We say sum is equal to num1 + num2. Be aware that while in this instance the + sign is being used for addition, it can also be used for concatenation, which we'll get to at a later stage. Great! We now can add our two numbers together. However, we can't see the result at the moment. This makes it difficult to tell if the calculation is working and if it's working correctly. So, how do we display the result of our addition? We can actually borrow a line from the default hello world program for this. You may have noticed that line of code that says Console.WriteLine("Hello World!");Well, a Console.WriteLine() is used to display whatever is between the brackets to the console window. We can therefore use it to display the result of sum. To do so, it would look like this: Now, we're ready to run our console app for the first time and actually see the result displayed in the console window. Go ahead and click Start. As there should be no errors, the program should compile and you'll be given a window which looks like this: This same logic can be applied to floating point numbers or doubles. Try it out for yourself and see what kind of results you get! Let's take a look at strings. We declare strings much like how we did for ints. We start off with the data type which in this case is a string followed by a name for the variable. In this case I'm going to use the variable to store my name, so, I simply call it name followed by the string value of "Dan". If you use a Console.WriteLine(), you can print that value to the screen as you did before with sum. Now, remember I mentioned concatenation before? Now's the time we're going to use it. So what is concatenation when it comes to strings? Concatenation of strings is when we take two or more strings and join them together. They don't always have to be variables. I can write a string in my Console.WriteLine() along with a variable if I want and it'll display it in the console. For example: Let's take a look at a bool variable. As I've said before, a bool variable is used for storing a true or false value. This can be used for checking certain criteria. For example, if you are over 18 or not after entering you age for validation. A bool value could be used. Let's look at how we declare a bool. As with our previous variables, a bool is declared much the same. The keyword followed by a name and value. It's important to point out, you don't always have to assign a value when declaring a variable. For a bool for example, it may not make sense to assign true or false until after a certain check has been made. Defaulting it to say a true value might create a problem. I can display the current value to the console as before using a Console.WriteLine(). In the next tutorial, we'll look at using if statements.
Until next time! |
Archives
April 2019
Categories |