Hello and welcome.
So we're now going to discuss how to use hexadecimal and binary in the C programming language so firstly
if we go back to the ascii table you can see decimal value and a hexadecimal value next to a decimal
value hexadecimal value.
All that this is is the way the computer displays it to you.
Everything in a computer is binary.
The decimal numbers you see here are just the way it displays that to you.
That's all that is now.
That is an important thing to note.
Anything you see if it's a capital A a capital B it is all just ones and zeros.
And the fact you see a is because this table the ascii table associates those binary bits with pixel
bits so it knows which character to display on the screen to you know hexadecimal is no different it's
just a way of showing a decimal in a different in a different format.
So you use decimal and hexadecimal to express binary values it's all the same things.
OK.
So go back to visual code and I want us to create a variable and set it to a hexadecimal value.
So go integer A equals zero x 0 x means that we're gonna we're about to express a hexadecimal value.
So the compiler 1 1 it's compiling your code should read that value as hexadecimal that that's what
it's saying.
So if we do 0 x 20 in here you've now you've now set a to 0 x 20.
And if you do print f we're gonna put this so I can show you the difference a.
Now this will be output it is decimal right.
So let's now open that up and compile it.
So back to CMB D paste that in JCC main dot c dash so dark forward slash main
and then domain you can see 32.
So what this means is hexadecimal 0 x 20 is decimal 32.
Now watch this.
You can do percent x here to display hexadecimal values.
So now if we provide a again so a will be output is in show first and then as hexadecimal next.
If we now compile that again and run that you can see 30 to 20.
So 20 is our hexadecimal value 32 is the decimal equivalent but let's go back to what I was saying earlier.
The thing is hexadecimal and decimal and binary they all equal the same thing.
That's how it works.
Zero X 20 is no different from our 32 decimal.
This this is just the way the computer displays it to you.
It is all just binary.
At the end of the day it is not decimal.
It is not hexadecimal.
Everything is expressed as binary.
And the computer can render it to us in decimal or hexadecimal and that is so important to know.
So hexadecimal 20 is exactly the same as decimal 32 two is just being displayed to us differently.
They are equivalent at the binary level and that is what you need to know.
Let's now discuss how to write binary values and see.
So if you do zero p one two three four one two three four and then get rid of this final zero input
one.
I'm going to change this to a shop and put a semicolon there.
So as you know there are eight bits and bytes.
So we should have eight bits here.
One two three four five six seven eight.
Yes we do.
So make sure the final zero is a one.
Now I want you to compile that I'm running that again so we can see the binary one is hexadecimal 1
and decimal 1.
So to do binary you start with zero B decimal zero B everything after is binary in binary values.
So if you now get rid of this and put a zero.
This should be two
which it is put a 1 here.
So it's 1 1 at the end.
And it should be three which it is.
So that is how you can assign binary in the C programming language you simply start with a zero B and
then the rest of the numbers are your binary value the first zero here means nothing.
The following zeros and ones are the value so the following after the beep.
So I hope that explains hex decimal and binary in C.
I know I haven't discussed how the hex numbers and binary numbers.
How how how they can be how you can understand them but that's because this I assume you already know
this.
This is a C programming course.
I'm T.
I teach you how to use them in the programming language so you can look that up simply binary is base
2 and hexadecimal is base sixteen.