Data representation and storage in a computer is fascinating.
In the last video, we looked at the decimal binary number systems.
In this video, we look at 3 more popular data representations.
I'm Tim Buchalka from the Learned Programming Academy.
This is my learn to code series right here on YouTube.
Are you enjoying the series?
Leave a comment on this video and let me know if you're enjoying it.
All right, on with the show.
Data representation and storage in a computer is indeed fascinating.
The 3 popular data representations we're going to
talk about in this video are hexadecimal, ASCII and Unicode.
Are you ready? Let's get started.
We've already learned that people manipulate numbers using the
decimal number system and computers manipulate numbers using the binary number system.
In addition to those number systems, a few more data
representation schemes come to mind.
Hexadecimal has key and Unicode.
Keep in mind the computer still stores all data using binary.
Let's look at each of these schemes and see their role in
data representation and storage.
The hexadecimal number system, often shortened to hex, is a base 16
number system made up of 16 symbols.
As you know, the decimal number system or base 10,
uses 10 symbols 0 through 9.
Hexadecimal uses the 10 decimal numbers and 6 extra symbols.
In hex, there are no numerical symbols that represent values greater than 9.
So the letters taken from the English alphabet are used
specifically a b c d e and f.
Hexadecimal a equals decimal 10, b equals decimal 11, c equals
decimal 12, d equals decimal 13, e equals decimal 14 and
hexadecimal f equals decimal 15.
Humans mostly use the decimal system.
This is probably because humans have 10 fingers, 10 digits.
Computers, however, only have on and off called a binary
digit or bit for short.
A binary number is just a string of 0s and 1s.
1 1 0 1 1 0 1 1, for example.
For convenience, engineers working with computers tend
to group bits together.
In earlier days, such as the 1960s, they'd group 3 bits at a time much
like large decimal numbers of grouping 3s like the number 123,456,789.
3 bits each being on or off can represent the 8
decimal numbers from 0 to 7.
000 equal 0, 001 equals 1,
010 equals 2, 011 equals 3,
100 equals 4, 101 equals 5,
110 equals 6 and 111 equals 7.
This system is called the octal number system, and we'll
not cover it in this video.
Remember, we're talking about how the computer represents and
stores data in binary, but can transform it into decimal for
human display and consumption.
Moving on as computers got bigger, it was more convenient
to group bits by 4 instead of 3.
This doubles the numbers that the symbol would represent.
It could have 16 values instead of 8.
Hex equals 6 and decimal equals ten, so it's called hexadecimal.
4 bits is called a nibble.
A nibble is 1 hexadecimal digit and is written using
a symbol 0 to 9 or a to f.
2 nibbles are a byte, 8 bits.
Most computer operations use the byte or a multiple of the
byte 16 bits 24, 32, 64 etc.
Hexadecimal makes it easier to write large binary numbers,
although hex is still not as easy as decimal for humans.
For example, binary 0010 0100 equals decimal 36 or hex 24.
So how did I get hex 24 or taking the first 4 bits or nibble 0 0
1 0 we convert it into 0 times 8 plus 0 times 4 plus 1 times
2 plus 0 times 1 equals 2.
As I mentioned, to software engineers hex 24 appears to be simpler to
visualize in binary 0 0 1 0 0 1 0 0.
Let's try one more.
Now this is handy stuff, so don't get too hung up on it.
Binary 0 0 1 1 1 1 1 0 1 0 0 0 equals decimal 1,000 or hex 3E8.
So how did I get hex 3E8.
Well, again, taking the first 4 bits or nibble 0 0 1 1,
we convert it as follows.
0 times 8 plus 0 times 4 plus 1 times 2 plus 1 times 1 equals 3.
The next 4 bits or nibble, 1 1 1 0.
We convert into 1 times 8 plus 1 times 4 plus 1 times 2 plus 0 times 1 equals
14 decimal which is alpha e and hex.
And the last 4 bits are nibble 1 0 0 0.
We converted into 0 times 8 plus 0 times 4 plus 1 times
2 plus 0 times 1 equals 8.
Now as I menti1d to software engineers, hex 3e8 appears to
be simpler to visualize than binary 0 0 1 1 1 1 1 0 1 0 0 0.
To finish our discussion of hex, the main reasons for becoming somewhat
familiar with it is because it's much easier to express binary number
representations in hex than it is in any other base number system.
As I said before, computers do not actually work in hex, but
consider that a byte is 8 bits.
If we divide the 8 bits into 2 nibbles 4 bits, the binary value range for a
nibble is 0 0 0 0 to 1 1 1 1 which is decimal 0 to 15 or 16 possible values.
So hence the use of hexadecimal which can represent the 16 possible values.
Now you hopefully have a basic understanding our computer stores numbers
using binary and how binary is translated into hexadecimal.
Up to now, we've only been talking about numeric data.
But what about other types of text.
For starters, how would a computer store alphabetic and
special characters like a comma, period, exclamation point,
left or right parentheses etc.
They're not numbers, right.
Does the system use another system for storing this type of information?
Well, it turns out that the computer uses binary
for this type of data also.
In fact, for any type of data, it uses binary, right.
So how do alphabetical and special characters get saved in binary.
If we're using alphabetic characters, special characters and numbers from a
keyboard, the computer uses a table of codes to represent these characters, a
very common system exists called ASCII which stands for American standard
code for information interchange.
The first version of ASCII came out in 1963 and it's still in use today.
Basically, ASCII is an 8-bit encoding scheme where a unique value is given
to each alphanumeric character.
In a nutshell, it's a standard way of assigning a value to
these alphanumeric characters.
As an example, the ASCII codes for the 3 letters that make up my name
Tim all in upper case are 84 73 77.
So t is an 84 or 0 1 0 1 0 1 0 0 in binary.
I is 73 or 0 1 0 0 1 0 0 1 in binary.
And m is 77 or 0 1 0 0 1 1 0 1 in binary.
So depending on how the computer views these binary numbers, they
can be considered as the number 84 or the letter t 73 or the
letter I or 77 or the letter m.
Because ASCII is a worldwide standard used on many computers,
that means that these codes will be the same and treated the same on
all computers all over the world.
ASCII was originally based on the english alphabet it has added an
upper and lower case and a range of other special characters like
the digits 0 through 9, exclamation marks, commas, parentheses and so on.
ASCII uses only 7 of the available 8 bits to represent a character.
By using 7 bits, we can have a maximum of 128 distinct
combinations, which means that we can represent 128 characters maximum.
Now this is pretty limiting for non-english languages and modern
computers have ways to go far beyond this range using Unicode and encoding
schemes like UTF-8, UTF-8 and UTF-32.
The UTF here stands for uniform transformation form.
The point is though that with an encoding scheme, there is a value
assigned and universally agreed upon for a given value, where t in
ASCII was binary 0 1 0 1 0 1 0 0.
In UTF-32, its value is actually multiple bytes.
So you've got 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0.
So the computer uses 4 bytes to store each character in
UTF-32 versus 1 byte in ASCII.
Now don't worry too much about it.
The point is that the computer is assigning a specific value to a
specific alphanumeric character so that a t on one computer
will still be a t on another computer.
So this type of encoding works for other types of data as well.
Ultimately, the data is still stored in binary.
But so let's consider one more type of data as I close out this
video and image your picture.
So in the example of an image which is much more complicated than
the 3 letters of my first name, it's still a similar principle.
An image for example a high-resolution picture of yourself consists
of lots of pixels, millions depending on the size of the image.
If you zoom in on the picture, you can see the individual pixels.
So your picture has millions of pixels.
A pixel needs to store information about the color of individual
pixels and the amount of storage space it requires depending
on the number of colors.
So 8-bit color is where 1 byte, 8 bits can be used to
allow the computer to assign a value of 256 colors in 1 byte.
We know that a byte can store a number between 0 and 255, so therefore,
we have 256 possible color values.
In that case, the computer would use 1 full byte per pixel
for every pixel in the image.
Today's computers use 24 or 32-bit color which is why higher resolution
images take up much more space, they have more ranges of colors per pixel.
Now I've dramatically simplified things here, but the main point I
want to make with binary is that a computer can store virtually
any type of data in binary.
It's a job of the app or program to use the data in the correct way.
All right, so that's the basics of hex on Unicode.
Drop me a comment in the video, and let me know how you found and whether
you've now got a better understanding of hex, Unicode and ASCII in general.
Moving on, in the next video, I'll look at integers, real numbers,
alphabetic characters and special characters in more detail.
Thanks for watching see you in the next video.
This is the part of the video where I meant to get all enthusiastic
and to ask you will quite literally beg you to subscribe to my channel
and to like the video, leave a comment and all that stuff.
Well, I'm going to leave that decision in your capable hands
to decide whether I've earned a like or a subscriber or a comment.
I'd be grateful if you do one, both or all three.
More videos will get out there in front of a bigger audience if
I get that level of engagement, but obviously it's your choice.
All right, so remember that this series was meant to
be watched in order.
So if you haven't watched from the start, then how dare you watch
my video series out of order.
Click the link over here to get to the first video in the series and
watch that if you want to see the entire series in order or come over
here and click to view the previous video in the series again your choice.
All right, I'm done catch you in the next video.