YouTube Transcript:
How computers use binary numbers
Skip watching entire videos - get the full transcript, search for keywords, and copy with one click.
Share:
Video Transcript
hi in this video let's talk about how
computers store data we'll talk about
binary numbers [Music]
[Music]
binary numbers are the systems that use
ones and zeroes to store data using
computer circuits so you likely know
that computer circuits have either an on
or an off value which are represented in
numbers as a one or a zero let's go back
to your school days do you remember when
your teacher taught you how to count by
numbers that were greater than a hundred
we used things like expanded notation so
8473 can be written like this 8 000 plus
400 plus 70 plus 3.
the idea here is that decimal numbers
have place values
so first of all place values in decimals
look like this
each place has a 10 as a base
and then there's an exponent so we could
write this 8 473
473
in a different form
we could say that 8 is the thousands
place which is represented as 10 to the
third power
the four is in the hundreds place which
is represented as four times ten to the
second power
seven is in the tens place which of
course is ten to the first power and
and
the ones place is really a disguise of
10 to the zero power remember in
exponents any number raised to a zero
gives you the number one as an answer so
understanding place value is critical to
understand how binary numbers work
let's look at an example here so i have
a binary number written on the screen
and i have the place values listed below
so each number that you see either one
or zero falls into a specific column so
the first column is the ones place it is
represented as two to the zero power
so when we say that binary is a base two
number system we're talking about the
base of the exponential problem
so when let's take a look at how we
would compute this answer
so we see that in this example there is
a one in the second place
the second place is represented as the
is the two to the first power
and the next number over we find is in
the two to the third power so what is
two to the third power it is two times
two times two so we'll call that the
eighths place so really we have a first
place which is the
ones place the two's place the fours place
place
what we have here is the eighths place
look ahead
we have another one coming up it's at
two to the sixth power
so what is two to the sixth
the answer is 64.
so this number is in the 64 place
what's the last one then it's 2 to the
seventh so double of 64
that's going to be 128.
so to compute the answer here we have to
take all of the places and add them together
together
so 128 plus 64 plus 8 plus 2.
if you add all those up and if i did my
math correctly we come up with 202 is
our number
so using place value is a way that we can
can
calculate a number even if it is not a
base 10 system
so why did we pick a binary number
system it's because we have these
gadgets that are binary computers in the
early days of computing we had vacuum
tubes which would store a value in the
computer's memory so a vacuum tube is
essentially like a light bulb except it
has a charge in it so it is either a
high charge or a low charge high voltage
or low voltage on or off and in the
early days these took an immense amount
of space so you can see here that we
have eight vacuum tubes in a row
each of these represents either one or a
zero a bit
let's switch over into a program written
in c sharp that will give us an example
of how this looks
so i am going to translate numbers into
their binary value i'm going to use this
statement here which is called convert
dot to string
and the numbers that i put in here are
the integer value which is going to run
from 0 to 255 in a loop and then the
second is a base number so we are using
a base 2 system so this will give us a
count of all of the binary numbers let's
see what it looks like
so here's the results of the program you
can see that we start our for loop at
zero so it says the decimal value is
zero and the binary storage is zero so
far so good you can see the pattern
starts to move along here when we get
along to
like three bits
so the number one one one represents the
number seven so if you were to add these
up here we have the ones place
the two's place and the fours place
that's four plus two plus one so that
gives us seven
let's scroll down to see where we have
the next bump up in place value so that
occurs down here at number fifteen and
sixteen so you can see that fifteen has
the value of 1 1 1 1. so add those
together you have 8 plus 4 plus 2 plus
1. so that gives you 15. if we want to
represent 16 then we have to go to the
next value down which is
1 with 4 zeros so the place that we're
looking at is a sixteenths place that's
ones twos fours eights
sixteen place so that's why we get a one
followed by four zeros
where's the next break going to occur or
where does the next
significant digit come in so that would
be double of 16. let's scroll down to 31.
31.
31 gives you the 1 1 1 1 1 and then we have
have
32 which takes a new place value so
let's double that again let's go to 64
and see what comes up so i'm scrolling
down to 64 and sure enough 64 begins a
new place value
the number 128 should be next in our
list let's scroll to that and you can
see that the difference between 127 and
128 is a significant value and then we
get to the end here and what was the
last item so i got up to 254 had i
gotten to 255 we would have included all
ones here
so this program here as you can see its
purpose is to convert decimals into a
base two value so we can see what those
look like in ones and zeros now let's
talk about storage units that are in
computers memory or on their disk drive
so we start off with the smallest here
which is one bit
that's a zero one one byte is the value
of eight bits
and then you can see we jump into
kilobytes then which is a thousand
twenty four bytes one megabyte one
gigabyte one terabyte petabyte and exabyte
exabyte
round off the title of the uh all these
different measurements so
1024 where did that number come from
well that is another one of those
doubled values so two to some power i
think it's nine maybe we'll give you uh
the value of 1024.
so that kind of tells you what the
number value is of each of these
measurements but let's get a concept of
how big each of these are so a bit is a
true or false value that's zero one one
byte is one letter from your keyboard so
the letter a b or c
then we have a kilobyte which is one
page of unformatted text
one megabyte is about a minute was worth
of music or maybe a photo that you take
a gigabyte is maybe an hour of video not
the highest quality video but a medium
quality or a word document that has a
bunch of pictures in it that's about a megabyte
megabyte
one terabyte is the size of a kind of a
typical hard drive in a computer and so
you could put a lot of things on one
terabyte you could fill up your hard
drive with all of the episodes from
famous tv shows such as law and order
the simpsons family guy friends the
office take all those together and you
have a terabyte worth of video a
petabyte is the next guy up and this is
starting to get into some major large
storage at least in our opinion so you
could take a video camera and record it
24 7 at pretty high quality
video quality and you could do that for
three and a half years and you would
fill up your one petabyte hard drive or
you could take 4 000 pictures every day
and do that for your entire life and
that would be a petabyte an exabyte is
about 11 million movies if they were in
high resolution uh the entire internet
would handle hundreds of exabytes of
data per day
and then finally at the very top is a
zettabyte so a zettabyte
is um a lot obviously
it's about estimated that we have more
than 30 exabytes of data stored on every
device in the world so that includes
every phone and every computer and every
server and every data storage facility
so we're in the astronomical range
that's really hard for us to conceptualize
conceptualize
so as a programmer you're going to be
required to understand the differences
between these types of storage units in
your programming language so that's what
i teach is computer programming and we
have to understand the difference
between integers and longs and floats
and doubles so let's take a look at how
these are categorized so in the first
column you find what's called integer
values so these are whole numbers so int
so uent is an unsigned integer so only
positive numbers can be stored in a uint
so you can see the rest of them are long
shorts and bytes and things like that
the floating points are where you would
have fractions or decimal points so
decimals doubles and floats are
different sized items for taking care of
decimal numbers
the object
data format is completely different than
any of these so we'll leave that for a
future video what is an object what are
objects how do you program with them
in characters we have two different uh
types of data storage a char is a single
letter a string is a bunch of chars put
together into a sentence and then lastly
we have logic which is a boolean
variable now essentially you could store
a boolean as a single bit true or false
in reality i think they use maybe a byte
let's take a look at two floating point
numbers so here's an example of a
floating point number it's a decimal so
this rounds off to the nearest penny you
might say it's nine cents but if you
were to look at a more precise value if
you wanted to go out to the tens of
zillions of digits
this is going to require a lot of data
storage so many many bits are going to
be required if you want to have very
precise numbers so if you're working
with currency in a program you're going
to want to have a pretty good
accuracy here you don't want to be
rounding off things
transactions are you know kind of
sensitive and if you obviously are into
scientific instruments then this is
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.
Works with YouTube, Coursera, Udemy and more educational platforms
Get Instant Transcripts: Just Edit the Domain in Your Address Bar!
YouTube
←
→
↻
https://www.youtube.com/watch?v=UF8uR6Z6KLc
YoutubeToText
←
→
↻
https://youtubetotext.net/watch?v=UF8uR6Z6KLc