WEBVTT

00:01.020 --> 00:10.780
Last time I introduce types like int char and double and before you get into explaining more about types

00:11.060 --> 00:20.320
I did something in the last lecture I did this really 10 and three this is what's called the comment

00:20.950 --> 00:24.950
and you'll see a comment above here as well.

00:25.180 --> 00:35.150
The name of my seat BP file variables the anti-common is ignored by the compiler.

00:35.150 --> 00:40.820
It's really just a way to mark something for programmers so I thought.

00:41.240 --> 00:44.310
Just explain that.

00:44.400 --> 00:49.330
So no this gets compiled this is just for us.

00:49.370 --> 01:00.620
So in this lecture I want to talk about more types and a little bit of why we have types and how their

01:00.620 --> 01:02.560
sizes.

01:02.750 --> 01:12.990
So I'm sure you've heard of binary before the ones and zeros and a bit you may have heard before as

01:12.990 --> 01:13.600
well.

01:13.620 --> 01:21.900
And that contains either the value 1 or 0 which means it's base to number.

01:21.900 --> 01:31.420
So our typical number system is base 10 which goes from 0 to 0 to 9 right.

01:31.440 --> 01:34.720
In this in binary is either 0 or what.

01:38.990 --> 01:52.680
So if we had a base 10 numbers say 123 and we'd understand the base number like this one

01:55.160 --> 02:06.890
one times 10 to that is power power to was

02:09.220 --> 02:19.180
you times 10 to the power of one plus three

02:21.990 --> 02:23.630
times.

02:24.430 --> 02:27.940
Ten to the power of zero.

02:28.540 --> 02:35.210
So meaning this is the ones so tenth power of zero just ones of time series three.

02:35.560 --> 02:41.230
And then this would be the tens because it's one to the power one doesn't change change the tune at

02:41.240 --> 02:41.960
all.

02:42.130 --> 02:50.310
So just be two times 10 or 20 and then 10 to the power of two which would be 100 times one is hundred.

02:50.620 --> 02:54.740
So all that added together is 123.

02:54.740 --> 03:02.970
So but if we had a 4 bit number what's so one bit is either there or one.

03:03.250 --> 03:11.270
So but if we had a forbit number say like this what would that be.

03:11.270 --> 03:17.960
What is the Momi the base 10 representation of that number.

03:18.340 --> 03:22.280
So this is not too difficult to do.

03:22.660 --> 03:32.410
So you'd say 1 times 2 to the power of three right.

03:33.540 --> 03:33.680
Right.

03:33.940 --> 03:42.470
This because this would be a power of zero to the power one due to the power of two and two to the power

03:42.470 --> 03:49.540
of three races in the very last one or the very low left most one plus zero times.

03:52.030 --> 04:03.300
Tines to the power of two was zero times two power.

04:04.100 --> 04:13.530
One was one times two power zero.

04:14.940 --> 04:15.600
Right.

04:15.670 --> 04:23.630
And all of that is equal to let's say eight Ciro.

04:23.770 --> 04:24.990
Right.

04:25.030 --> 04:38.690
Zero us one and just nine this number 1 0 1 in binary is really just our nine.

04:39.450 --> 04:49.090
And this is an easy easy way to determine what is or how to actually make a

04:51.990 --> 05:02.800
translate let's say a binary number to a base 10 or so all of this is really just to say that

05:05.530 --> 05:17.910
if you want a well a byte that you may have heard of as well like a megabyte or kilobyte is really 8

05:18.030 --> 05:20.010
bits so two.

05:20.100 --> 05:28.570
So this is four bits and really we want a byte is 8 bits

05:32.240 --> 05:36.060
and all our types are actually measured in bytes.

05:36.070 --> 05:41.230
So how how big our types are is usually measured in bytes.

05:42.170 --> 05:53.700
So the size I said before completely system dependent actually and we can actually figure out what those

05:53.700 --> 06:00.470
sizes are if we use what's called the size of operator.

06:00.510 --> 06:05.440
So let's find out what the sizes of the types that we use last time are.

06:05.460 --> 06:20.640
So let's say see ouch and do the int size of an inch is and then we just say size of it.

06:25.650 --> 06:26.500
And we'll see.

06:26.510 --> 06:32.840
All our other types as well the size char is

06:48.230 --> 06:48.760
ch

07:00.420 --> 07:02.390
you look at double as well.

07:18.520 --> 07:20.410
So if we run this

07:26.000 --> 07:27.620
so we'll see.

07:27.620 --> 07:33.490
So like I said they're all measured in bytes so the size of an int is 4 bytes.

07:33.830 --> 07:42.570
So that's 32 bit and the size of a char interestingly is just one byte and float is the same as in it

07:42.570 --> 07:46.700
it's 4 bytes and double is double a float.

07:46.710 --> 07:48.090
So it's eight bytes.

07:50.670 --> 07:57.220
So because of their sizes types only have a certain value range they can be.

07:57.240 --> 08:00.690
So for example in in

08:05.720 --> 08:11.740
an integer which can have the values are in the positive zero or negative.

08:11.950 --> 08:13.010
Right.

08:13.710 --> 08:19.480
It can only have the values of negative to shew the power

08:21.950 --> 08:29.940
of 31 and it's 31 because 4 bytes is 32 bits.

08:29.940 --> 08:37.020
But since we have negative values it has to be divided by two which would knock off.

08:37.050 --> 08:42.460
So it should be 32 bits but since we have to divide what two we have to knock off one.

08:42.690 --> 08:46.570
So it's only 30 power 31.

08:46.830 --> 09:05.560
So it's you can go negative 2 to the power of 31 to 2 to the power of 31 minus 1 and it's minus 1 because

09:05.560 --> 09:09.110
of zero.

09:09.240 --> 09:11.360
You have to count zero as well.

09:11.610 --> 09:14.570
So it's always minus 1.

09:14.590 --> 09:19.610
So this is the main reason why we have different types or one of the main reasons.

09:19.840 --> 09:26.920
Because they are different sizes in the computer's memory and we can change the value ranges by adding

09:27.280 --> 09:29.740
what's called an unsigned

09:32.550 --> 09:42.600
unsigned keyword say unsigned int x is zero right.

09:42.610 --> 09:47.710
So unsigned means it can't be negative and must be positive.

09:48.710 --> 09:52.680
And unsigned also doesn't change the size of the type at all.

09:52.700 --> 10:08.170
It will only change the value range thus it will have the range from zero to two to power 30 to rate

10:08.200 --> 10:15.630
as it's 32 bits or bytes minus one because of zero.

10:15.660 --> 10:22.720
So this is now 30 to 32 instead of power 31.

10:22.760 --> 10:28.210
It was up here because we're completely eliminating all negative numbers

10:31.460 --> 10:38.870
so this is not the only reason why we have types in the language though.

10:38.990 --> 10:43.630
And note that int and float are the same size.

10:43.760 --> 10:45.150
But let's try.

10:45.170 --> 10:53.100
Let's try this let's get rid of unsigned So let's say we have an X or it's called something better.

10:53.250 --> 11:11.950
Now and float float in footwell won't give it 3.20 for a number and let's say we say interval equals

11:11.960 --> 11:13.220
to fluvial

11:17.950 --> 11:23.820
and then let's print out each value.

11:27.850 --> 11:30.720
Now is

11:39.140 --> 11:48.090
this not tell us.

11:48.260 --> 11:54.550
CH So see how the info is 3 right.

11:55.900 --> 12:03.490
It's not 3.1 4 this is because of how the computer will interpret the integers.

12:03.490 --> 12:06.780
Integers have to be whole number.

12:07.420 --> 12:21.120
But if we did something like bow equals six and then we kind of reverse this.

12:21.290 --> 12:24.780
Now here like that.

12:24.790 --> 12:31.530
And then we ran it.

12:32.440 --> 12:45.030
Well some compilers actually say 6.00 actually are actually no sorry since this actually my fault book

12:45.410 --> 12:47.840
is only a fluke.

12:48.480 --> 12:54.870
Sorry.

12:55.420 --> 12:57.040
So it classics.

12:57.160 --> 13:00.780
But some some will actually output six point 0.

13:01.240 --> 13:07.360
Instead Not just six.

13:07.470 --> 13:10.270
So it actually interprets completely differently.

13:12.550 --> 13:13.060
So

13:16.020 --> 13:22.560
remember that even if they're the same size different types are interpreted differently.

13:22.560 --> 13:31.350
The compiler often gives you some kind of warning or maybe even error sometimes if you just start assigning

13:31.350 --> 13:32.250
types.

13:32.250 --> 13:38.810
So here here we're assigning this into vowed to be the float for example.

13:38.850 --> 13:44.040
So if you just start assigning types without being careful and thinking about doing might end up with

13:44.040 --> 13:46.860
something you didn't want to happen.

13:47.660 --> 13:52.580
So in the next lecture we'll start talking about arithmetic operators operations.
