37 JS Integer Literals hex numbers – Javascript

Last updated on July 13th, 2020 at 11:45 am.

37 JS Integer Literals hex numbers - Javascript Tutorial 2018

 
This video is taken from the full course that will teach you HTML, CSS, Programming concepts and Javascript .

Transcript :

Hi, and welcome back.

In the last 2 videos, we looked at the decimal and the octal numbers.

Now let’s go to the next one which is the hexadecimal number which is a base 16.

So to represent a hexadecimal number, it will be indicated by zero and a small ‘x’ or zero and a capital ‘X’.

So if you want to represent 16, if you want to represent 15 I mean, it will be ‘0xF’.

That is equals to 15.

If the interpreter sees this, it will know that, ‘Oh.

This is not a string but this is a hexadecimal number’.

It can be zero and a small ‘x’ or a zero and a capital ‘X’.

So if I come back here and before I go to the browser, we know that hexadecimal numbers have base of 16.

That means there are 16 different digits or characters that can be used to represent any number in the hexadecimal system.

So we know if a number is hexadecimal, it can only include 0-9, and the numbers that are greater than nine, that is from 10 up to 15 will be represented by ‘A’ until ‘F’.

So that means, 10 is ‘A’, 11 is ‘B’, 12 is ‘C’, 13 is ‘D’, 14 is ‘E’ and then 15 finally is ‘F’.

So these are all the possible numbers from 0 to 9 and then ABCDEF.

So if I come back here to the browser, I’ll just delete this entire thing.

Let me just remove these ones as well.

So if I want to represent a hexadecimal number, it is ‘0x’, if it is ‘1a’.

The interpreter, the JavaScript interpreter will see this and just know that this number is a hexadecimal.

It should be used as a hexadecimal number.

So let’s see what number this is when it comes to a decimal number.

So if I display that, this is the same as 26, ‘1a’.

And if I want to represent 10, I can just use ‘a’ and display, there we go.

That’s 10.

If you want to represent 11 that’s ‘b’.

Display that.

You want to represent 12, there.

13, there.

14, there.

And then finally 15, and then finally 15, 15.

If I run, display this it will give us 15.

And if I want to go to the next number which is 16, it will be ‘10’.

That will give us, that’s the same as 16.

Then I want to go to 17 and then I want to go to the next number, 12.

If I display this, this is the same as 18.

So if I want to represent the next one 19, it will be or rather 19, it’ll be that.

And if I want to represent 20, display 20.

So it’ll just go all the way like that and then at 19, you display, is equals to 25.

And then 20, display is equals to that and you can even use bigger numbers.

So let’s say that you want to use a bigger number, ‘20000ef’.

And then I display that.

That’s that number.

So the point is if you want to represent a number as a hexadecimal, you can use a small letter ‘x’ or a capital ‘X’.

So ‘0X’, as soon as the interpreter sees that, it will just know that this number, whatever comes next it should be interpreted as a hexadecimal number.

So if I display that, it’ll give us this number.

And now, what if we have, what if we have something that is not part of the numeral system within the hexadecimal numbers.

So that, if I tried to display this, it’s going to give us this error because ‘r’ is not within A-F.

It’s not within A-F.

And it is not within 0-9 which represent the hexadecimal numeral system.

So the point of this was this.

In your integer literals, you can use a decimal number, you can use an octal number, you can use a hexadecimal number, you can also use a binary number.

So we’re going to look at binaries in the next video.

So the point was that you can use any of these number systems.

And you have to know that there’s a difference.

So for instance you saw that if you say zero, if you start a number like ‘013’ and you try to do the square of this number, you’re going to get a number which is not what you’re expecting.

For example, you’d probably expect the ‘013’ would give you 169, which is not, which would not happen because, because this number has a leading zero, it would be treated as an octal number.

And therefore, this number would be interpreted as something different.

So let’s continue in the next video.

And in the next video, we’re going to look at binary numbers.

We’re going to look at the binary integer literal which is base 2.

So I’ll see you in the next video.

Click the button below to watch this full course:

Comment Here

Need WordPress help? Linux Server help? Talk to us.

  • We are your own WordPress customer service.
  • We set up Linux servers and install or migrate WordPress. Learn more here.
  • We support WooCommerce too.
  • Check out our WordPress customer support plans here or contact us below .

If you have any questions regarding WordPress support, Linux server support or any of our services, feel free to reach out or read more on our services page.

Join this free course:

How to host multiple WordPress
websites on a VPS

Close me!