where it really makes sense to have more precision
precision
so compare the different types of
storage and how you can use a maximum
and minimum range for each of them so a
boolean is the first row in our table
and it is simply a byte it's going to be
either a true or false so not much of a
range there a char and a byte are both
ways to represent an 8-bit number or a
byte and so we can go from 0 to 255 in
that range so a char is
is
a letter
so in the ascii character symbol table
65 has been assigned to the letter a
so whoever got to assign that first
picked 65. first for a lowercase a
the number is 97. so there is a key that
corresponds between letters and numbers
so chars and bytes are really the same
thing but are interpreted differently by
the computer
a short is a double length thing it's
two bytes and you can see that the range
here goes from a very narrow range
really negative thirty two thousand
seven sixty eight all the way up to
positive thirty two thousand seven sixty seven
seven
so the negative sign takes one of the
bits and then the remainders are used
for the numbers you can see ins are much bigger
bigger
longs are huge floats are like massive
so with a precision comes a cost so
really the cost is the memory usage so
if you're using
longs for everything you're wasting
memory because if your values of your
game or your program never exceed the
limits of an integer then there's no
there's no reason to use a long
so let's switch back into visual studio
i'm going to show you some examples of using
using
these numbers such as
an integer and a short and a float so
the first thing i see here is a variable
called score and i've set it to be
32768 which we're going to see why is
significant in a minute but the range of
this uh integer is quite large so we
could we could do up to 10 to the ninth
power of uh
place values so that's in the billions
however the short value you can see here
is only up to 32 000 so shorts have a
pretty small limitation and then we're
going to work with the difficulty level
here in the game which is going to be a
decimal of 4.2
so let's scroll down a bit now and we're
going to see that when we try to convert
from one to the other we get a problem
so if i say short score is now going to
be equal to score
this doesn't work however the reverse
should work i'm going to comment out the other
other
so we can convert score
from short score so we can go from the
smaller value into the larger without
any trouble however we cannot go the
reverse so
we will lose some significant values of
what's going on here so in other words
we have a limitation of storage now we
can fix this problem if we do something
called casting so i'm going to put a
parenthesis in here and i'm going to put
in the word short
which is going to say that we're going
to take score and we're going to convert
it into a short value which then allows
us to assign it to the type called shortscore
shortscore
now we could have some problems with
that and we'll find out in just a jiffy
what those problems are so let's let's
change score to something like
9000. so it's a fairly typical number
it's not outside of any range of
anything and then we're going to print
both of these so i'm going to say score
equals and now short score equals
something they probably look a lot like
each other they should be identical value
value
so when i run the program sure enough i
get the value it says score equals 9 000
and short score equals 9 000. no problem
now the problem will occur if i try to
go beyond the range of what the short
score is so let's go right up to the
edge of it 32 000 767
and run the program this should still work
work
so we can see the results are that the
score and the short score are both the
same thing so no problems with that
conversion we will encounter problem if
we try to go outside the range so
remember the maximum value of short
score goes up to seven six seven what
happens if we push it just one beyond
that we're going to go to 768. so now
we're out of bounds
will the program crash
let's find out
uh-huh so you can see that the program
did not crash
instead it switched this into a negative number
number
so the way that the numbers are stored
you says that the the most significant
bit in the value is a one or a zero
which is for the sign of the integer and
so by pushing it beyond the boundaries
we have turned the positive number into
a negative so this wraps around to the
opposite end of the number line and so
you can get some pretty strange results
if you go outside the boundaries of a short
short
now let's try another conversion i'm
going to take the float value difficulty
and try to store it into the score which
is an integer
obviously we've got a red line here
we've got a problem it says you're not
allowed to do that so did you want to
try a cast so i'm going to say show
potential fixes add the explicit cast
and now it's doing a integer so
can you convert a float to an integer
well you can if you make some
assumptions like we're going to chop off
the value
if the decimal point and just give you
the integer part let's see if that's
what happens
so let's put a print statement in first
of all that says hey we're going to
print the difficulty first and then
we'll show you the score and the short
score as a matter of fact i'm not
interested in short score anymore so i'm
just going to comment him out let's go
ahead and run the app
so you can see the results at the top it
says difficulty was 4.2 and when we
converted it into score it was an
integer value of 4.
what happens if i try rounding it to a
different number so let's go to 4.9 so
will it round it up to 5
as you can see the result is still 4. so
doing a cast into an integer is called a
floor operation in other words it always
rounds it down to the nearest integer so
it is possible to convert from a
floating number into an integer value
however you're going to lose the
decimals and you're going to round off
to the nearest lowest integer
so now that you've seen some ways of how
numbers are stored let's talk about how
storage has actually changed over the
years so here's an example of a memory
card you could have bought in 2005 and
one that was in 2014
probably for about the same price each
way one is a
and twenty four times larger than the
other so gigabytes and megabytes are
obviously different scales and we've
grown accustomed to streaming videos and
downloading huge files let's compare the
different storage items that are in a
binary system so way back in the
beginning as i mentioned we have these
vacuum tubes then later in the 50s we
transitioned into transistors which are
much smaller but they still hold charges
ones and zeros then we've gone become a
next generation up which is integrated
circuits and then microchips which have
grown smaller and smaller more complex
using less power and more efficiency so
there's different ways to arrange
microchips together so we're all
familiar hopefully with the cpu idea cpu
is the largest and most complex of the
memory chips that are in your computer
however there are others and they're all
designed to do different things but the
idea of integrating everything on one
circuit and making a gadget that looks
like a small cockroach is the idea of making
making
simpler and more cheaply when you're
trying to manufacture a computer
so we've shrunk the size of our storage
over time so the number of transistors
that were in the 1950s were somewhat
better than the vacuum tubes was greatly
improved but we've kept up that same
improvement on generation after
generation after what's known as moore's law
law
so moore's law is the idea that we
noticed or mr moore noticed that the
intel corporation
was cramming more things into smaller
spaces about every two years or so they
would double the number of transistors
that they could put on a microchip
so that is possible because they have
smaller and smaller gaps between the
wires and the pathways and the
transistors that are in their integrated
circuits so way back in 2002 they had a 180
180
nanometers of space between items on a
chip so a nanometer is a one billionth
of a meter very small you need
microscopes to be able to detect this
kind of thing we're getting down to the
size of almost molecules and atoms on a
chip and as you can see we've gotten
smaller and smaller however you get to
the top of the graph and you can see
that the
the exponential growth has leveled off
we're still getting smaller but the
physics are getting harder and harder to overcome
overcome
and so in 2015 there was a 16 nanometer
manufacturing process
currently 2021 is when i'm making this
video a 5 nanometer process is
considered state of the art and so
they've shrunk it even further so we're
getting to the point where instead of
using tools to do the etchings or the
making of the chips we're into light
waves and x-rays and gamma rays and small
small
little uh changes in the actual
molecules of the substance that we're
working on so very very small means less power
power
and faster response times
now if you're one of the students in my
programming classes i'm going to
eventually assign you this the
temperature conversion app it'll be a
very simple app and it will use integers
and floats and the conversion between
the two using temperatures such as
fahrenheit celsius and calvin and so
that's a different video but i invite
you to stick around to join me for class
if you're not one of my students please
Click on any text or timestamp to jump to that moment in the video
Share:
Most transcripts ready in under 5 seconds
One-Click Copy125+ LanguagesSearch ContentJump to Timestamps
Paste YouTube URL
Enter any YouTube video link to get the full transcript
Transcript Extraction Form
Most transcripts ready in under 5 seconds
Get Our Chrome Extension
Get transcripts instantly without leaving YouTube. Install our Chrome extension for one-click access to any video's transcript directly on the watch page.