How Computers Work: Binary And Data

Saturday, April 6, 2019

How Computers Work: Binary And Data


Description

In the Bits of Binary twos-complement video, Christopher Mast asked "what do you do about the fact that all the binary numbers you're listing in the negative are assigned to trigger special characters and foreign letters?" That's a great question and today at the House of Hacks, Harley will talk about how computers work binary and data.

References:

Here at House of Hacks we do tutorials, project overviews, tool reviews and more related to making things around the home and shop. Generally this involves wood and metal working, electronics, photography and other similar things. If this sounds interesting to you, you may subscribe here.

If you’re interested in learning more about the House of Hacks' values, here’s a playlist for you.

And here’s the most recent video.

For a written transcript, go to How Computers Work: Binary And Data

Music under Creative Commons License By Attribution 3.0 by Kevin MacLeod at http://incompetech.com.
Intro/Exit: "Hot Swing"

Transcript

In the comments on the recent video about subtraction using twos complement, Christopher Mast asked a great question:

"what do you do about the fact that all the binary numbers you're listing in the negative are assigned to trigger special characters and foreign letters?"

This is a great question!

I gave a brief answer but wasn’t terribly satisfied with it.

So in this video, I’m going to dive a bit on how computers use numbers to represent all the different types of data that they work with.

By the way, Christopher has a great channel called “Legion of Weirdos” where he covers topics for your party time conversation so you don’t have to talk about your day job. Check it out.

At their core, computers just work with binary numbers.

As we saw in the Bits of Binary series, we went from 0 to 255 with 8 bits and that's all zeros to all ones with only 8 zeros or ones.

As computers got newer and more bits were added, each time they doubled the number of bits, from 8 in the old computers to 16 on some newer ones and they can count all the way up to 65535.

Adding more bits to 32 bit, again doubling, it can count all the way to 4 billion.

And with 64 bits it can count all the way to 16 billion billion, or an exabyte.

But in the end, they're all just positive integer numbers from zero to all ones, depending on how many ones there are.

So, how does the computer deal with characters?

Or negative numbers?

Floating point numbers?

Or any kind of data for that matter?

This is the topic for this video.

But first, if we’re just meeting, I’m Harley and this is the House of Hacks where we use our God-given skills, interests and talents to make things in the workshop out of things like wood, metal and electronics.

Part of making new things is understanding how old things work and so that’s why we’re looking at computers so we can have better understanding for future projects.

The most basic answer to Christopher’s question is: everything in a computer is just a positive number and we use those positive integers in different ways, with different mappings, depending on context.

Let’s get into some examples.

As we've discussed, computers only deal with binary numbers, in this case 8 bits, from 0 to 255, all zeros to all ones.

When a programmer wants to use numbers in this range, they just define the memory as unsigned and when they do that, the computer will treat 0 as 0, 1 as 1, all the way up to all 1s as 255.

When a programmer needs negative numbers, then they define the memory as being signed, and when they do that, the computer will treat all binary numbers that start with 0 as positive integers from 0 to 127 and it will treat all numbers starting with 1 as negative numbers from -1 to -128.

And as long as the programmer maintains this context of treating these numbers as signed then everything works out just fine.

Now, let’s look at characters.

In the early days of computers, there were a number of different ways of treating characters inside the computer.

At the end of the day, the one that ultimately won out is something called ASCII.

And it breaks down the numbers into groups of 32.

0 to 31 are what are called control characters and these were used in the early mechanical input devices to physically control the input. Things like moving the carriage to the beginning of the line and ringing a bell for the operator notification. Things of this nature. They start out with 0 as null and continue down to 31 for special characters.

The next group of 32 was for special characters and numbers. It started with space being defined to 32, exclamation point, quote, hashtag, the numbers were in the middle here, and at the end at 63 was a question mark.

The next group of 32 were the capital letters. It started with an "at" sign at 64, capital A was 65, capital B was 66, capital C was 67 and so forth down to 95 which was the underscore character.

And the final group of 32 were the lowercase characters. It started with a back accent character, "a," "b," "c" being defined as 97, 98 and 99, continuing on down to 127 which was treated as a delete character.

Now to get to Christopher’s point, the extended character set came in later and it defined numbers from 128 to 255, which happens to correspond to the negative numbers that we saw in the twos-complement video.

These characters are things like an "a" with an umlaut over it or "u" with an umlaut over it for foreign languages and special line drawing things on CRT screens.

The way the computer differentiates between whether it should treat it as these special extended ASCII characters or a negative number is basically just the context of what the computer programmer has told that memory should be treated as.

Whether it should be treated as a signed number, in which case they're negative numbers, or whether it should be treated as a character in which case they're part of the extended ASCII sequence.

So it's really just the context that defines how these numbers are being defined and mapped, and how they're ultimately being used.

And any kind of data in your computer really is treated the same way.

Floating points are just ultimately numbers that have special meaning assigned to them when they're told that the context is floating point numbers.

And any other data is the same way.

For example, this video that you're watching, the audio and the video that you're seeing are just numbers inside your computer that are being displayed on your screen and output through your audio devices.

If this sounds confusing, occasionally it is, but generally it’s not too bad. Context is a real good indicator of what's going on.

And it’s not completely without precedence. Consider spoken language.

Here's a combination of letters in English that has two meanings, the same spelling and different pronunciations.

It could be "minute" meaning a unit of time or "minute" meaning a small amount.

And here's another combination of symbols. The same three letters.

But if you're in English it means one thing.

If you're speaking Spanish it means something else.

And if you're in trig and math, it means yet a third thing.

Same symbols, different meanings, different contexts.

Thanks again Christopher for the great question and don’t forget to check out his channel up here in the cards.

Also up there in the cards is a link to the Bits of Binary playlist if you're interested in a deeper dive into binary number systems and over here are some videos that YouTube thinks you'll be interested in.

I'll see you there and in the mean time, remember when making things...

Perfection's not required. Fun is!