In section 15.1, and we'll converting binary to decimal, decimal to binary and binary to hex in this particular section. We alluded to this in the first section, but we will review of parts of it again. It is important to be able to convert binary numbers to their decimal equivalent. To convert a binary number to its equivalent decimal value, multiple the weight of each column by the digit value in that column, then sum the products obtained.
We have done before, but here we have a binary value and we want to convert it to what is the decimal equivalent. If we write out the values of each digit, so it'd be one, two, four, eight, 16, 23, 64, and 128, and then if we sum those values and we'll have a one, and we'll an eight, and a 16, and 128. If we add these up, let's see, eight and eight is 16 plus six is 22, 23, three carry the two, and we have five and we have 153. We could confirm that with our calculator. If we look at our calculator here and go to decimal and type in 153 and then click on binary we should have 100110, and that is the correct value. That's binary to decimal.
Then, we'll go to converting decimal to binary. If we have a number expressed as decimal number, we should be able to convert it to a binary number. One procedure for decimal to binary conversion is divide the decimal number by two, write the remainder down as a bit in the converted number beginning with the least significant bit, LSB, repeat the first steps until the quotient of zero is obtained. This is quite simple actually. We'll show one example here. We're going to convert 100 to binary. The procedure is to divide by two and keep the remainders. If we start out with 100 and we divide by two that would equal 50, and we have no remainder. We would put down the zero here and that would become the least significant bit. Then, we will take 50 divide that by two, and that will give us 25, again remainder of zero. We'll keep the zero. Then, 25 divided by two and that would be 12 with a remainder of one, and we will keep the remainder which is one. Then, 12 divided by two will give us 6, again another zero remainder. Then, six divided by two will give us three and that will give us another zero remainder. Then, three divided by two will give us one with a remainder of one, so we'll keep the one. Then, let's see, then we will have one divided by two is going to be zero, but we'll have a one as a remainder and we will keep the one.
We can evaluate this. Let's see, if we do our method here of one, two, four, eight, 16, 32, 64. If we add up the weighted values here we will have a four and 32 and 64. If we add four plus two is six plus four is ten, carry the one, and there we have it. That would be 100 base ten, and so we took the 100 and we converted it to binary. This is the method that is addressed in your textbook. I have a preferred method that I like, and this is not in your book but I just like this and I mentioned this in the previous section where I just create a block of a table and I write in the weighted values, and it would be one, two, four, eight, 16, 32, 64, 128. If I want to convert this to binary I simply fill in the blanks and subtract. We would not need 128. It would be a zero here. We would, however, need 64, so I put a one here, go over here to 64, subtract 64 from 100, I would get 36, and I would need 32, so we go subtract out 32, that would remain left with four. I would have a zero here, a zero here. I would need the four, so I put a one here, subtract out four, that is zero, and I'd have zero and zero. This should be the value that we just, one, one, zero, one, zero, zero, that is, in fact, what we had there, one, one, zero, one, zero, zero. That is my quicker method. Do whichever method suits you.
To increase the efficiency and simplicity of working with binary numbers, they are often converted to hexadecimal or base 16. Conversion between binary and hexadecimal is simple. Begin at the radix and mark off groups of four binary digits. The radix, if you had a value, say you had one, zero, zero, one, one, one, zero, one, and the radix would be, this point here, this is before we go to the decimal, and you would mark off four digits here. One, two, three, four, and then mark off four digits like that.
We place each group of four bits with the hexadecimal digit and we'll look at the table for what those values would be. Here we have the decimal number, one, and this is just going up to number 15. Here are the hexadecimal equivalents. Remember, hex is four 16, and this simply means actually these are base 16 numbers, hexa base two or base 10, and we call it hex because there are 16 values, and so we actually we would start at zero and we would go to the letter F. F is equivalent is 15, but remember you have a zero so that makes it 16. In hex, let's see, hex looks just like decimal up to number nine, but then instead of having 10, we will have the letter A, and then B for 11, C 13 and up to F for 15. Then, these are the binary equivalents over here.
Let's do some of the conversions that we had mentioned. We're going to convert these binary values to hex. The methodology is simply to group them in groups of four starting at the radix, so right here. We would go, one, two, three, four, so this would be one group, and then this would be the next group right here. What we would do is we'd evaluate the four digits that we have isolated. This is going to be equivalent to the number one. These four digits, if we did the one, two, four, eight, this would be 15, but in hex that would be F. Then, here we have, again, we would do the same thing, two groups of four, and so this would be one, two, four, eight. What's this? This is going to be 12, 13, and in hexadecimal that would be a D. One, zero, zero, zero, that would be an eight, and then this one here would be, this one's kind of easy, this would be F, F.
One of the things that it mentioned a couple screens back was that this simplifies binary. Students always look at me dumbfounded, how in the world is this simpler? The simplicity is simply that for every four bits of binary you can replace it with one bit of hex. In all of these cases, here we have eight bits of binary, and we have replaced it with two digits of hex. Something to keep in mind is that your computer does not use hex, a computer uses binary exclusively. Hex is just there to make it easier for the user. You don't typically talk in hex, for example, if you see memory addresses in your computer they are always represented in hex values, but I'm departing. Let's check out our calculations here. Let's pull up our calculator just to make sure that we have done this correctly. The way we would do this, by the way, I would mention that Windows has a calculator built into it that you could use for this function as well. Let's click on hex, and notice you have a new row here of values you can click in, so we'll say F and F1. Then, if I click on binary that should be this value. It's one, one, one, one, and that is, in fact, correct. Then, let's go to the next one. The next one is eight and D. Click on binary. There we are, we've got that one, and then the final one, hex, and we go F, F, and again click on binary and it should be an eight once.
This has been a quick introduction to calculating and converting numbers between binary decimal and hex. Here, we have gone from binary to hex. Let's see, there was our table of decimal, hex, and binary. This was a decimal to binary and that method that I prefer. This is decimal to binary using the divide by two method which is the one that your book uses. Then, we did decimal to binary. We should know that by now. That completes our conversion section.
Video Lectures created by Tim Fiegenbaum at North Seattle Community College.
by Ikimi .O
by Jake Hertz