[MUSIC]. Let's go back to our road map and look at the next topic that we'll be covering. we're going to focus next on integers and floats, the representation of numbers in in memory. That's going to be an important precursor before we can man, look at all the instructions for manipulating that data values. So this section is going to cover the representation of integers. Both signed and unsigned. And how we treat integers and c. talk about some shifting and signed extension operations that will be important for arithmetic. And then we'll close with a section on floating point numbers. basically, how do we represent binary numbers that are fractions rather than just integers? And then, we'll get into a little bit of detail on the IEEE floating point standard for floating point numbers. And how we do floating point operations. And the rounding that they entail. As well as look at floating point numbers and see. There's a lot more to floating point numbers. And we, we'll leave a lot of those topics to the text to cover. but we will do some of the basics. But before we get to integers Just wanted to talk about a encoding problems in general. So suppose we have a 52 card deck. A, you know, the typical playing card setup with 13 cards of each suit organized into four different suits. and we want to figure out how to represent these in binary numbers how do we use zeros and ones to represent all these cards, well we could start by thinking about the operations we want to be able to do on the cards so we probably want to be able to tell if a card is higher than another. or if they're the same suit that might help us think about the kind of encoding we have, lets take a look at some examples, so heres a very simple encoding to start with we have 52 different cards, so lets use 52 different bits, with bit corresponding to the card that we haev set to one. So that would let us use 52 bits of a 64 bit word, let's say. In what's called a one hot encoding. And meaning that there's only going to be one bit set to one, all the others will be set to zero. So we can have the first bit represent lets say the ace of clubs. Okay and the next bit represents the two of clubs and so on. What are some of the drawbacks to this? Well it's going to be really hard to compare values and suits because we have individual bits throughout those 52. where we have to look for the value in the suit of the card and we sure have a large number of bits to represent 1 card an entire 64 bit word. This is called a 1 hatting code where only 1 bit is on another possibility to do do a 2 hotting coding where we might use 4 bits to represent the suit and another 13 bits to represent the 13 possible values of the card. So now two bits would be set to one. So the fir-, the first bit in the suit might be set, to indicate the suit clubs and the, the first bit in the value might be set to indicate an ace. okay. So now it's a lot easier to tell if two cards are of the same suit, because they'll have the same 4 bits here. And, we can tell, if a card is greater than another, by looking at the position of the 1 in the remaining 13 bits. But that's still a bit cumbersome. It's easier to compare suits and values but it's still a large number of bits. in this case 17. This is what's called a two-hot encoding now, because we have two bits set to one for each card. Let's continue with this exercise and look at two possibly better representations. we could just do a binary encoding of all 52 cards, we only need 6 bits to represent 64 diferent numbers so we can take care of 52 in just 6 bits, that would allow us to fit a card into just a bit and use the low order 6 bits to do that. So that's kind of nice. It all fits in one byte. and it's much smaller than the one or two-hot encoding. But how can we make the value comparisons easier? the suit comparisons easier. we're still going to have all the cards numbered from one to 50 bit, one to 52, and that will not make it easy to do those comparisons. so we can do something that's a bit of a hybrid, we can use two bits for the suit, four bits for the value. Two bits for the suit because we have four possible suits, so we need four possible binary bit patterns here, 00, 01, 10 and 11. One and then four bits for the value. Because the card can be anything from an ace to a king 13 different values. Okay so this makes it now easy to still do that suit comparison, and just check if a number is smaller or greater than another take away the value. Okay. So, let's take a look at how we would implement these operations if we were doing it in in C. So, if we wanted to check if 2 cards are of the same suit, what we would do is have 2 bytes representing each card, Okay? Maybe an array to represent a five card hand. We would take two cards out of the hand and ask if they're the same suit. And this function sameSuitP is implemented here below. It returns a boolean value just zero or one. And takes the two cards as, arguments. What it does, you'll notice, is, it takes the first card, and does a bit wise and with the suit mask. What is the suit mask? The suit mask is a special value set to hex 3, 0. Why hex 3, 0? Well that corresponds to 00110000. You'll notice that when we do a bit wise and with this mask, we will only have non zero results for these two bits. All the other bits will necessarily be zero. Because we have a 0 here and 0 ended with anything will result in a 0. So this will essentially extract the value of the suit form the card representation. It will only have a nonzero value possibly in these 2 bits okay. So, then we can do an exclusive OR with the suit of the other card. Okay and why do we do an exclusive OR? Well remember, an exclusive OR says either one is true or the other is true but not both. Okay? So, we would only get a perfect zero result If these two suits matched exactly, in other words, they had the same zeros and ones in these two locations, if they have that, then the result will be all zeros. And that's a bouillon false, and by taking the complement of it logically, we can say then that, tho, those two cards match. That our result is true. Okay. So what we actually implemented here was the opposite of the x or by using the not. In otehr words, we said, rather are the two suits different bits. We, we're asking, are they the same bits? By just doing the compliment of the X0. All right, that would have been the same as saying this using the equals, equals boylean operator that says these 2 things exactly match I just showed you what we could do with the boylean operators Alright. Let's take a look now at comparing the values of two cards. Again we have our array of five cards, our hand. And we compare two cards, card1 and card2. So which has the greater value? Is card1 a greater value than card2? So you'll notice here what we're going to do is Apply a different mask to the card. This mask is value 0f, the value mask. It has a one in the low order four bits. So we're getting f-, the low order four bits, which represent the value and zeroing the suit. And the way we get the suit zeroed is by applying the logical AND with a mask that has zeros in these positions. So now the result won't necessarily be there and if we compare 1 of those extracted values to the other we can simply get the greater relationship between the 2.