# 014 – ASCII Representation

Now, you may be asking yourself,
what’s the point of all this? We’re converting from
decimal to hexadecimal. We’re doing this
two’s complement. What is the purpose? And the answer of course is, to
impress your significant other. Nothing will impress them
more than whipping out some of these conversions. No, there’s important
things that happen. And particularly, in the
early days of computing– I was going to say
it was important. It’s important now,
but it was maybe more– you’d use it more. Now, a lot of stuff happens
kind of behind the scenes. But it’s important
to understand, as a computer scientist, what
is happening behind the scenes. Because that context helps you
to address problems and things that come up. So for example, when computers
were first being created, everybody was doing
their own thing. And everybody was
representing characters, for example, which
everybody usess– so let’s say the letter A– one person might have
said, well, an A to me is whenever I have all zeros. That represents an A. But somebody else
might have said, I actually do numbers
first, so for me it’s a 1 that’s represented
by all zeros. And an A I actually represent
after I’ve done the 10 digits. So I represent it
with a 0000 1010. And so what happened is, as
computers became more popular, is that the American National
Standards Institute, or ANSI, created the American
Standard Code for Information Interchange,
or the ASCII table. And originally, the
ASCII table was 7 bits. Now, the number of
bits is important because I could ask a
question about how many things can be represented. If I have two binary
numbers, how many things can I represent? And the answer is– I could just go through them– I could say 00 is one thing, 01
could represent another thing. So this could represent
an A, this one could represent a B.
10 11 and that’s it. I have nothing else
with two digits. OK? But the easier way, again,
to figure that out is to say, what base am I in? I’m in base 2. And how many digits are there? Well, there’s two. So the answer is four. Right? Four things I can
represent with two digits. Well, so in the ASCII
table originally, there were seven bits. But they were
represented in binary. So we had 2 to the 7th, which
gave us 128 different options– different things
we could represent. And so they went through
and assigned them. They said let’s
standardize this. And so if I go here and
let’s see if I can do this. Pull up an ASCII table. Notice, that they went through
and said, if it’s all 0s it’s a null. If it’s 1 that’s a
start of heading, and they went through and
anyway, at some point here we get into the alphabet. So here’s the digits, and
then at some point here’s 65– we get to an A. Now,
and A is represented by the decimal number 65. But notice what it
says right here. hx, meaning
hexadecimal, is a 41. And then it goes through octal– for octal, and a lot of times
they’ll have the binary. They don’t in this one. Let’s see, just
out of curiosity. There we go. There’s binary. And so if you go
pull up a document– a text document–
here’s my alphabet. Well, there’s my
alphabet with uppercases. A 65 decimal is
a 41 hexadecimal, which is a 1000001 binary. And that is how the A character
is represented in a file. If I just pull up a you know– if I just pull up Notepad here,
and I type of character, A, I save this somewhere,
what’s going to happen is it’s actually going to be
saved in memory as a 01000001 assuming I’m using ASCII. OK? Well, they decided eventually
that that wasn’t quite enough, and so they went
to 2 to the 8th. Write it up a little higher. That gave us 256
different options. And that way in
the ASCII table– so if we go look at
this ASCII table again– maybe– then we got to the 127– and then they came
up with what’s called extended ASCII, which is what
we use for many things today. So that added in all these other
symbols that we see sometimes– accents and whatnot that
are more commonly used. There’s a copyright sign. So all these symbols
were assigned a letter. And it could have
just as easily been– they could have started
out with 000 being A, but they came up with this
standardization and now everybody uses that. Well eventually, as computers
got around the world, there’s other languages that use
completely different symbols. And so they eventually
moved to a– you can save text
files as Unicode files, and if you go to Unicode,
then they moved to 16 bits to store the characters. So we went from 2 to 8 to 2
to the 16th, which is a lot. You can do that
math if you want to. It’s a lot of
different characters. And that way they
can represent– actually, I know what it is– 65,356. It’s a lot. Anyway, so they can do
all the Russian characters and Arabic characters
and Chinese characters and that’s in Unicode. But the problem is, if you’re
storing 16 bits in a file for each character,
that’s twice as many bits than you were for ASCII, and so
the file becomes twice as big. And so if you don’t need the
extra characters in Unicode, you can store your
file as an ASCII file and it will only store
8 bits per character. But if we were to go save
this file and look at it, it is going to be
8 bits in size, because we stored 1
character, and each character is 8 bits or one byte. And so when you start to
see these file sizes– so if I just save this out
somewhere to the desktop, and then pull that up– so on the desktop– go look at the blah file. Well, it’s going to be–
it’s going to show as bigger. Let me see if I can– 0 bytes. It’s not going to show well
the way I’ve got it set up. But that’s how– so
when we get a file, how do you get to
your file sizes? Well, if I write
the word Spencer, each of those characters
is a 1-bit character stored as an ASCII character. So the S is the capital S– if we go back to
our ASCII table– is a 123. That’s octal. It’s a 53 in hexadecimal. It’s an 83 in decimal, but
in binary it’s a 01010010– and so on and so forth. So that’s one place
that we see this and we use these conversions
is in the ASCII table. Where else? What about images? And we’re hitting the
magic 10 minute mark so I’m going to go ahead
and stop and continue this discussion on
in one last video. Spencer out.