From the course: Symmetric Cryptography Essential Training
Binary representation
From the course: Symmetric Cryptography Essential Training
Binary representation
- [Instructor] In this section, I'll talk about how data is represented using binary numbers, and that's zeros and ones. For the most part, cryptographic algorithms operate on raw data and they don't care about the format of that underlying data. It's important to understand that when we're using computers, it's not actual letters or numbers being stored behind the scenes. Some historical crypto systems that we will look at later actually do operate on individual letters and numbers, but modern crypto systems do not. One of these zeros or ones, a single binary digit is called a bit, and eight bits together form a byte. The byte is typically the smallest unit of data that a computer operates on. If we have thousands or millions or billions of bytes, we'll have kilobytes, megabytes, and gigabytes and so on. To explain how nice round numbers are represented in binary, we're going to do something that should be extremely familiar to you, counting. In the decimal number system we're used to, which is base 10, let's use the number 493 as an example. That's subscript 10 indicates that we're working in base 10, so if you see a different number there in the future, that means that we're working in a different base. The number three in that number is in the ones place, the number nine is in the tens place, the number four is in the hundreds place. This is all very elementary school-level stuff, but you'll see why this is important in a minute. And then when we add these all together, we get the original three digit number as the sum. We have three times one, three is in the ones place, nine times 10, nine is in the tens place, four times 100, four is in the hundreds place, and that gives us 493, base 10. Shouldn't be anything surprising here. Counting in binary, it's the same pattern just with a different base. Where in decimal there are 10 digits to choose from, the binary system has two, so it's base two. As an example, let's use the number 1101 with subscript two there, meaning this is base two, it's not 1,101, I will just say 1101. In that number, the last digit represents the ones place, just like in base 10, the zero is in the twos place, the one is in the fours place, and the first digit one is in the eights place. So as we go from right to left, they're in higher and higher places. So in the final value in base 10, if we're thinking about it in the number system we're most used to, we have one times one for the one that's in the ones place, we have zero times two for the zero in the twos place, we have one times four for the one in the fours place, one times eight for the one in the eights place. If we add all these together, one plus four plus eight, that gives us 13 in base 10. So 1101 base two is 13 in base 10. With a different number, we can show this as a table with each digit having its own place and we multiply the place times the digit down to the bottom value. So in this case, we have one byte, that's eight bits, with the value 01000110 base two, and we can see that that equals 70 in base 10. 64 plus four plus two because we have one in the 64s place, one in the fours place, and one in the twos place. And then when we add all those together, we get 70. So is that it? Can we represent anything else in binary? So far, what we've seen are just nice round number values, integers. But as you'll see in a moment, we can represent a lot of other things too.