In this lecture, we're going to discuss data types and we're going to start off talking about what
scalar types are.
And scalar types represent a single value, and rust has four primary scalar types and they are integers,
floating point booleans and characters.
So I went ahead and did is I used cargo new to create a new directory called data types.
And in here we're going to look at integers, integer, literals, floating points, booleans and characters.
To start off, we're going to start off with integers and integers.
B eight bit, 16 bit, 32 bit, 64 bit and 128 bit.
So if we wanted to create.
An eight bit integer, we can say let.
X of type I eight, which is going to stand for integer that is eight bit equal.
And then for this we'll just do ten.
So now if we just went ahead and printed this out.
We would get ten.
So now we'll go down here, cargo build and cargo run.
And as you can see, ten was printed out at the bottom.
So now integers can also be signed or unsigned.
And what that means is that if it's signed, it can be positive or negative.
But if it's unsigned, that means it won't have a plus or minus minus.
So only use unsigned integers if the value you want is for it to always be positive.
So it works the same way.
So we'll say let y and then we'll do you for unsigned eight.
And right here you can see where we have all of our unsigned bits as well.
So we have eight, 16, 32, 64 and 128.
So we'll do eight again and then we'll just enter this one to also be ten.
So this is creating an unsigned eight bit integer.
So no matter what we did, it will always be positive.
So the next thing that we can talk about are integer literals.
So what we'll do here is we'll call create a variable called decimal and we're going to assign it zero
to underscore five five.
So this is going to create a variable called decimal and it's going to contain a value of 255 and decimal
format.
So we can also do this with hex.
So if we do that, create a variable called hex and assign it a hex value that will also be.
You 55.
Correct.
That typo?
Nope.
There we go.
And likewise we can also do this with octal.
So we'll do octal as well and it'll be zero.
The big with the little circle.
Circle with a little.
So there we go and do 377, which will also be 255.
And then finally we can do binary.
And set it to zero be 1111 underscore 1111.
And that will be 255.
So now if we went ahead and printed all of these out.
And then for sake of time, I'm going to copy and paste.
And we will go.
A simple
hex, octal and binary cargo build, cargo run.
And as you can see, we have 255 for all of those above.
Another one that I can point out is a bite.
So we can say let bite equal.
Lowercase B.
Apostrophe Big A.
Close it off.
And this is going to print out the ASCII value of what a Capital A is.
And I believe it is going to be 64 or 65 and it is 65, as you can see right there.
So now what we're seeing right here and this is just a little tidbit we we created a Y value, a Y variable,
and we never used it.
So if you want to silence these unused variable warnings, you can put an underscore in it.
So now if we cargo build in card go run.
It's a completely clean all the warnings are silenced but we could also comment it out with two forward
slashes and it'll turn the text screen that's pretty universal and programming languages on how to comment
in your code.
So what we'll do is we'll comment all this out.
And we'll go down and now we're going to look at floating point.
So floats are going to work a lot like integers and the way you instantiate them.
So what we'll do is we'll, we can do it this way.
So we'll do X again equals 2.0.
And what this is going to do is it's going to create an F 64, which stands for float 64 bits.
And this is default because on modern CPUs.
It's roughly the same speed as.
Floating point 32.
So if we wanted a floating point 32, we could do it this way.
And it's the same same thing.
But floating point 64 obviously is going to give you better precision.
So that's why it's default.
Next we will look at booleans.
So boolean is just going to be true or false.
So the way we can do that is let.
Be for true, equal, true.
And then let f boolean equal false.
Either way it works.
They both are the same thing.
So the reason that this work works is because.
Rust's compiler and runtime is smart enough to infer the type so it's going to know OC hey, the variable
t is set to true.
So I know that this variable is always going to be a boolean.
So you can, you can implicitly tell it with that or you can let it figure it out on its own.
Either one works kind of a preference.
And lastly, the next one we're going to look at is a character type.
So we'll do.
Let's see.
Four character equal.
See?
And it's the same thing.
So if we wanted to print that out.
And put that in there.
Clear it off.
Build it.
Run it.
And as you can see down here, we printed out this see character.
Now there's a couple of arithmetic.
Operators that we have you can do you have plus.
Minus.
Multiply divide and then remainder.
So we'll create a couple of variables ten let be equal.
Five And then what we'll do is just demonstrate.
But the remainder is.
Um.
You know, ten plus five.
We all know how that one's going to work.
So just for sake of time, we'll do a remainder.
So we're going to change B to four and we'll say let remainder equal to A.
Remainder B.
And then we'll print out.
What the remainder is.
And it should print out to.
The arithmetic is super simple.
The remainder one is one you might not have seen before.
So yeah.
So the sign is how you get.
You remainder, and now you've learned the basic scalar types of rust.
And the next lecture, we're going to talk about the compound types such as tuple arrays.
So I'll see you then.