 All right, Mr. Gibson here with your next lesson in cryptography. And today we're going to be talking about positional number systems, which is something that we use all the time. Our base 10 number system or decimal, as we call it, is a prime example of a positional number system where every character, depending on where we write it or its position within the number, assigns some sort of value to that number that's not just implied based off of the character you've used. So when we define a positional number system, we say the base of the number system does a couple of things. It identifies the value of each position in the system, and it also tells you how many characters are needed to represent numbers. So for example, we use base 10. That tells us that every position within our digit of our number is a certain power of 10, and there's also only 10 different characters that we need to represent our numbers. Those characters are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. So the example we have on the screen, 1, 2, 7, which we would read as 127, and we know that because the 1 is just a representation. There is one group of 100. The 2 represents two groups of 10s. That's a power of 10. And the 7 represents 7 groups of 1, and 1 is also a power of 10. It's 10 to the 0 power. Just like 100 is 10 squared, 10 is 10 to the 1. So each of those positions tells us something about the value. The 2, we might think about that as representing 20, as opposed to if we started the number with a 2, that would be 200. So where the characters appear assign some value. We are most familiar with base 10 numbers, so we would call that decimal, and there's a couple of examples there, 17, 22, 99, 1,000. And again, decimal uses the numbers 0 through 9. Now we're going to represent those same exact four quantities using different bases. So another commonly used base in computer programming is octal. So as you might see from both the name and the base number, octal is a base of 8, and it uses the characters 0 through 7. So the number 17 in base 10 becomes the number 2, 1. We might read that as 21 because our brain is so trained on decimal. But the characters 2, 1 and base 8 is still 17. So it gets a little confusing when working in other bases when we try and read them out loud. The number 22 in decimal becomes the number 26 in octal, same quantity even though they look different. And so on down the line. Another common representation of numbers in computer programming is hexadecimal, so base 16. And our characters for that, this is where it gets a little tricky. Now like octal where we reduced the number of characters, so we just don't use 8 and 9. Hexadecimal needs more characters than what we typically have available. So we're going to go 0 through 9 like normal. But when we get to our 10th character out of the 16 that we need, we're going to switch over to the alphabet. So a quantity of 10 will be represented by A, a quantity of 11 will be represented by B, all the way up to a quantity of 15 represented by the letter F. So while we might say 17 in base 10, 11 in hexadecimal, 1,000 in decimal is 3E8 in hexadecimal. And we're going to talk in just a second about how we can convert back and forth between these. So you don't have to worry about that quite yet. And then probably the most commonly known alternate base number system that's used in computer programming is binary, only two numbers. So we just use the numbers 0 and 1. So the number 17 in base 10 becomes 1,0001. And the number 1000 becomes 111110100. And again, we're going to talk about a convert over to that in just a moment. But these are the ones you're going to want to be familiar with when we're working with cryptography and programming because different types of ciphers when we start using computers might implement operations in different bases. And that'll be a lesson that we'll cover in just a little bit is how do we do mathematical operations with these different representations of the numbers. Here's a nice visual that kind of shows you counting in the different number systems. So the third row labeled decimal in the blue is counting probably like we are used to counting. But we can see the counting taking place in the alternate number systems as well. So you can see that kind of binary is growing in the fastest. Octal kind of somewhere in the middle with decimal and then hexadecimal. If we let this run for just a little bit, we'll see. Continues to grow, but we need fewer characters. And that's part of the reason why people like hexadecimal is that it requires fewer characters or fewer positions rather to represent the same size numbers. So you can see that hexadecimal got up to like five something only only two places used where binary had like, you know, eight in there. So it's a little more compact way to write especially large numbers. Because it's not always obvious which base our number is going to be in when we write down the characters like three and then a seven like is that is that three seven thirty seven or is that three seven as a base eight number or a base 16 number. So these are some conventions that you'll see depending on the context. So base 10 numbers you would just write 1717 no additional information needed. If you want to write the number 22 and base 10 another way we could do that which is common when you're programming is the prefix 0 and then the lowercase letter D to represent decimal and then you just write the number after after the D. Base eight the number 17 would be to one and then a subscript of eight and then likewise the number 22 in decimal when we convert to octal becomes to six and we can represent that with a zero and then a lowercase o as the prefix similar types of notation for base 16 and base two. You can use a subscript that denotes the base of the number that you've written with the characters or hexadecimal can have a prefix of zero X and binary will have a prefix of zero B. All right, let's take a look at actually doing some conversion of other bases into decimal. Let's just start with kind of a refresher how we take our normal base 10 numbers and we convert them to a value in our head. So we've got the number of 4237 4237 and under each place I've written the value of that position. So the seven is 10 to the zero. So again, that's seven ones under the three. We've got 10 to the one, which means we have three 10s under the two. We've got 10 squared. So we've got two 100s and then under the four. We've got 10 cubes. So that's four 1000s and we can kind of write it out like that. So four times 10 to the cube plus two times 10 squared plus three times 10 to the one plus seven times 10 to the zero gives us the quantity that we're looking for here as decimal. Now this one's already in decimal. So that doesn't really illuminate anything to us, but having that strategy is going to be helpful when we do work on other bases. So for example, let's take a look at the binary number one zero one one and say we wanted to figure out what that was as a decimal. We can use the value of each position to help us convert. So like we did before we can kind of work from left to right. The first number one indicates to us that we have one group of two cubed. So one times two cubed. That's that's eight plus zero of two squared. So we got none of those. So that's add on zero and then we the orange one. So one two to the one will add that on. So now we've got eight plus zero plus two and the last one is one group of one because two to the zero is one. So we add a lot all up and we get 11 written as a base 10 number. We can do the same thing with hexadecimal again as a reminder B is the basically equivalent to the number 11 whereas E is equivalent to the number 14. So that'll become helpful here in just a moment. So we're going to convert these to decimal by again same operation. So the number two tells us we have two groups of 16 cubes B tells us we have 11 groups of 16 squared seven tells us we have seven groups of 16 to the one and E tells us we've got 14 groups of 16 to the zero. So we can just throw that into a calculator and we'll crunch out the number 11135. So again, it's the same number just two different ways to write it to be 70 hexadecimal 11135 base 10. Going the other ways a little bit trickier, but it's not too bad. So let's convert decimal numbers to other bases. So let's say that we've got our binary number. Sorry, our decimal number for two and want to convert it to binary. So the first question is what is the biggest power of two that is less than the number we're working with. So we know that two to the fifth is 32 and that is smaller than 42. The next largest power of two to the sixth is 64 and that's bigger than 42. So we know that this number is going to be no bigger than two to the fifth. Sorry, we know that this number will require no more digits than the one in the two to the fifth position. We call this number a six bit number and binary each position is referred to as a bit. So two to the fifth is the largest bit that we need and will need no more than six bits to represent this number. So now that we know that the first position of the number is one in the two to the fifth position, we need to figure out the remaining bits and we know that in total the remaining bits need to account for the the last 10 of value of 42 that first bit accounts for 32 out of the 42 the remaining five bits have to account for the last 10. So we need to think about, okay, if I need to add 10 more to the value here, what's the next biggest power of two that is smaller than 10 and that's two cubed. So I'm going to start filling in some of these blanks here. I now know that the from going from left to right, I need one zero one and two to the fifth, two to the fourth and two to the third respectively and that gets me up to a total of 40. So I need to represent two more with the remaining three bits. Now lucky for us, there's a position that represents a value of two and that's the two to the one spot so we can fill that up. And at this point, the bits that we've written account for all of the value we need from this number. So that last spot must be a zero. So again, we can verify the similar way that we just saw. We have one group of two to the fifth one group of two cubed and one group of two to the one together those things are 32 eight and two, which totals up to 42. We do the same thing with hexadecimal. So if we have the the decimal number 541, there are two groups of 16 squared. 16 squared is 256. There's two groups of that that fit into 541 because that that would be 512. That means that we have a remaining value of 29 that we need to account for. So if we need 29, I know I can do that with one group of 16 that gets me up to 528. And now we have a remaining 13 that we need to account for with the last position and 13 as its own character and hexadecimal. It's the character D. So to one D is equivalent to 541 in decimal. So that's that's the quick version of what a position on number system gets you multiple ways to represent the same number. We can convert back and forth to decimal. And we could even there's some algorithms for directly converting say from binary to hexadecimal or octal to binary. But for the purpose of this course just going back to decimal and then decimal to your new system is probably going to be the easiest way for you to think about it. In a future lesson, we're going to learn how we can work with operations on these numbers, but that's it for today. Thanks for watching and we'll catch you in the next one.