Transcript
  • Computer Science

The Octal Base (Base 8)

From the class:  The Binary Number System

All right, we've got one last one that you're going to see in computing, one last base that we need to look at, which is called octal or base 8. And this is a pretty cool one because it actually relates directly to a functionality that we use in our Mac operating systems or Unix or Linux if you're using those, which is the file permissions that we set.

And if you've ever seen a file permission that looks something like some weird command change mod and then 777 or 765 or something like that, it directly relates to octal. These are actually octal numbers. So we'll come back to that and I'll show you what that means. We'll get a little extra bonus in this video. But let's talk about the base 8 system first.

So just like we did before, let's come over to the right and get a sense of the multiples. And so if we start off at 8 to the 0th power, just like any of the other bases, that's going to equal 1. And 8 to the first power is going to hopefully equal 8 and 8 to the second power, 64. And we'll just go up to a few more here. So you see these are growing by powers of 8. So 512. So it's going to grow a lot faster than base 2, but not quite as fast as base 16. So it's sort of somewhere in between. And 8 to the fourth is going to get us all the way up to 4,096.

OK, so then the symbols that we're going to use in the base 8 system is there's going to be eight symbols. So we always have the same number of symbols as we do the base. And just like before, we're going to start off at 0. So we'll see it's 0, 1, 2, all the way up until we get to 7. So this is eight symbols.

And we can do computations and figure out the numbers of octal just like we were doing with the previous number. So let's say, for example, we want to represent the number 8. Well, we'll start here. And we'll say that this is 8 to the 0th power, 8 to the first power, 8 to the second power. And if we want to represent the number 8, we can just put a 1 in the slot here.

And we could put any of the eight symbols. So 0 through 7. But we'll just need a 1 and that's going to be 1 times 8 to the first power, which is going to equal 8. And what would happen if we put a 7 or something in this slot? Well, now we would say 7 times 8 to the 0th power, which is 7 times 1, which is equal to 7. So in base 8 or an octal, the number 17 is actually equal to 15 in base 10. So same kind of arithmetic that we were doing with the other base systems.

So let me cut to the chase here to show you why this is interesting as it relates to computers. Remember with base 16, we were able to cut down the number of slots that we needed by four each time. And it's sort of similar with base 8. Notice that 8 is actually 2 to the power of 3. And that relationship is important.

Let's write down 3 bits. So we've got 1, 2, and 3. And so in base 2, this is, again, 2 to the 0, 2 to the first, and 2 to the second. And what is the largest number we can represent with three bits? Well, 2 the third is 8 minus 1 is equal to 7. So 7 is the largest quantity we can represent with three bits.

Well, with base 8, we only need one slot to represent the number 7. And so that's going to be 8 to the 0th power, which is 1 times 7, since we have 0 through 7 as symbols. So we've just gone from three spots down to one spot.

So how does any of this relate to file permissions on Unix based systems? So file permissions. It works differently on Windows, but on Unix systems, the file permissions work similarly, whether you're on a Mac or whether you're on Linux or any of them. And the way it works is that every file can have three different groups. And so three different groups of people. You have the owner of the file, and then you have the group for the file.

So the group could just be like admin or something like that. And then you have everyone else. And for each one of these people, or each one of these sort of groups, you have three different file permissions. So one is going to be the ability to read the file. Let me get another color. You can read the file. You can write to the file. Or you can execute the file. So we'll just call that x. So this is read permissions, write permissions, and executable permissions.

So you could represent each of those as a bit. And we could say that we have three bits represents the permission for a particular group. Either the owner of the group or everyone else. And we could say that this bit here is a 1 if you have read permissions or a 0 if you don't. And we could see that this bit is a 1 if you have write permissions and a 0 if you don't. And finally, this can be a 1 if you have executable permissions and a 0 if you don't. So we need three bits to represent this information.

So let's do a couple of combinations so that you get a feel for it. So this is, again, 2 to the second power, 2 to the first power, 2 to the 0 power. We're going to treat this as a binary, our base two number to start with. And let's just say that you only have read permissions. So you can't write and you can't execute the file. Well, the base 10 number for that is going to be 1 times 2 squared, which is going to be equal to 4.

Now let's say that you have read and write permissions. So let's come over here and instead of this being a 0, we'll make it a 1. OK, so now we're going to have 4 plus 1 times 2 to the power of 1, which is 2. And that's going to equal 6. So if you have read and write permissions, that's going to equal 6.

So let's write these down as separate ones. So this is going to be read only. But then we have 4 plus 2 is going to equal 6. And that's going to be read and write. And then let's say you can also execute. So we'll just make this a 1 as well. Well, now that's going to be 4 plus 2 plus 1, which is going to equal 7. So that's going to mean you have read and write and execute permissions.

OK, so you can go in and figure out all the different possible combinations here. But let's get back to the octal system. So what we could do with this way of doing file permissions is we could say for every group here, we can have the three bits. So one, two, and three, one, two, and three, and one, two, and three.

So this would require nine bits and three for each type of person or each group for the file. But a much easier thing to do would be to just use octal. And that way we could just put a number here to represent some combination of these bits. And then we'll just have three numbers.

So in octal, for example, which works well because we have three bits and we only needed one spot for that. So we're going to have just some number between 0 and 7. So if we want to say that you have read, write, and execute, we can just write the number 7 in octal and that means the same.

Now, if we were to write the number 5, that would be 2 squared plus no write permissions plus execute permissions. So now this would be 2 squared plus 1, which is equal to 5. And if you see 6, that's going to be 2 squared plus 2 plus 0. That equals 6. So this is going to mean that you have read and write but not execute permissions.

So whenever you see file permissions like 766, what this is actually saying is that the owner the file can read, write, and execute. The group owner for the file can only read and write, but not execute. And let's just say that we make this a 0. That would mean that everyone else cannot do anything. They can't read the file, they can't write it, and they certainly can't execute it.

So this is probably the most common example of where you'll see base 8. But now you know how to go back and forth between base 8 and base 2 and why it's useful in computing.