Last updated on July 13th, 2020 at 11:45 am.
Hi, and welcome back.
So in this video, we want to continue from where we left off in the last video.
And in this video, let’s see something that can help us understand this from 0 to 7 with the octal numbers.
So if I come back here, let me just remove all of this.
And you can see these ones, that’s an ‘o’ not a zero.
So if I display that, you see it’s 10.
If this is 7, this number is going to get interpreted as an octal number because the numbers here are all represented from 0 to 7.
So if I run, if I display this, this number is equivalent to 15.
Let’s say we have 1234.
This number, the way it is, if we try to display it, it is equivalent to 679 as a decimal.
So this number was interpreted as an octal number.
What if we change this into 8 and bear in mind that here we have a, we have this zero.
Let’s see what happens if we have a zero and we also have an ‘o’.
So if I display this number, you can see we get a bunch of errors and that is because there’s this ‘o’ here.
So if I remove this one, this ‘o’ and then let me take this one back to 3 so that we can have this shown back to us.
Let me just remove everything to clean the screen.
And then, if I come and display this, you see this value is the same as 743.
So what if I come here and I put 8.
The number begins with zero.
What do you think is going to happen? Bear in mind that we have a rule that says that octal numbers can only be digits from 0-7.
So that means that if at any point there is a number that is greater than 7, that number whether it begins with one zero or begins with 10 zeros, it will be interpreted as a decimal number.
So if I come here and I display this one, it returns back to us this number and it will return it back as a decimal number because within these numbers there is 8.
That means that there is no way this number should be interpreted as octal because in octal numbers, numbers can only be represented with digits from 0 to 7.
I just wanted to talk about that at least to bring some difference in terms of zero and that.
So always bear that in mind.
If you add a zero before a number and within this number, there is no number that is greater than 7.
All numbers are less than 7.
That number is going to get interpreted as an octal number.
Let’s do one last example before I end the video.
So if I say ‘012 * 012’.
So let’s say that is the result that you’re expecting and you try to run this the way it is.
So you display.
You see it gives us 100.
That is because in octal, 12 is the same as 10.
So always bear that in mind.
If you add a zero before it, there is a high possibility that number is going to get interpreted as an octal number.
You must always find a way to remove this zero especially if the user is the one adding these numbers and you want the number to be always decimal, a decimal number.
Find a way to at least remove the zeros.
You can use regular expressions or any other way that you can think of to remove a zero before the number.
Any leading zero, remove it.
So that’s it for this video.
And in this video, we have seen a clear distinction between the zero and the no leading zero in decimal and octal numbers.
So in the next, in the next video, let’s look at the hexadecimal even though we had looked at it in one of the last videos.
Let’s just go and look at it again in the next video.
So I’ll see you in the next video.
Click the button below to watch this full course: