House of Hacks: binary
Showing posts with label binary. Show all posts
Showing posts with label binary. Show all posts

Friday, June 12, 2020

How to make a binary clock: design

Description

Want to make an Arduino project a bit more complicated than blink? In today's episode of House of Hacks, Harley starts a project on how to make a binary clock. This project will use an Arduino and be presented in multiple parts. Today, the first part will be the overall requirements and design. In future videos, the software, circuit and finishing it off with an enclosure will be covered.

Resources

  • All the information to make this project: https://www.house-of-hacks.com/p/arduino-project-binary-clock.html
  • If you just want to buy one: https://amzn.to/3eGXFVD (Amazon affiliate link)
  • Get a digital version of the new Arduino poster by signing up for the House of Hacks newsletter: https://list-optin.house-of-hacks.com/arduino
  • Or a printed copy of the poster can be bought on the House of Hacks store: http://store.house-of-hacks.com

Contents

  • 0:00 Project introduction
  • 0:59 Welcome and about House of Hacks
  • 1:19 Description of BCD
  • 2:14 BCD for binary clocks
  • 3:05 Project requirements
  • 4:02 Controlling the LEDs
  • 5:45 Tracking the time
  • 6:18 Adjusting the time
  • 7:23 Arduino selection

About

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 to make a binary clock

Here's a list of the tools I use.

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

Transcript

A number of years ago, at a software conference, one of the evening activities as an outing to a hands-on science museum.

While there, I noticed and picked up this binary clock.

It uses something called BCD encoding and I thought it'd be kind of cool to make my own version of this as a project.

Technically, it could be done with some simple logic circuits and a timer.

But this would involve more hardware design and wiring than I wanted to be involved with and so I'm going to go the easy route and use an Arduino.

This is going to be done in four parts.

Part one today is the basic requirements and design.

Than as I'm waiting for parts to come in, I'll go over the software design and how to actually do some testing without having a complete circuit finished.

The third video I'll assemble all the circuits and get it running.

And then the fourth video will be creating an enclosure for it.

Welcome to the House of Hacks. If we’re just meeting, I’m Harley and I make stuff out a variety of materials.

For example, in this project, we're doing design discussions, and software and electronics and mixed media for the enclosure.

If making a things out of a variety of materials in the workshop is something that's your thing, consider subscribing and you won’t miss future episodes.

BCD is an acronym for Binary Coded Decimal and this was an encoding system that IBM came up with nearly a 100 years ago in the 1920s for use in their early mechanical devices.

As early computers came on the scene, they took this basic coding that they used and expanded upon it to use in the computers.

It was called EBCDIC at the time and was actually used until relatively recently.

Interestingly, early in my career, I had to write an ASCII to EBCDIC conversion routine for use by our business partners.

Before going to the whiteboard, a couple notes.

First, the code and schematics for this project, is available for free download off of GitHub.

And second, a commercial version of this clock, kind of like the one that I picked up at the conference, as well as all the materials I'm using in the project are available on Amazon. I’ll leave links for everything down in the description below.

In BCD, each column represents a decimal digit, coded in binary. The first column is the tens digit for the hours, the second is the units column for the hours. Next, we have the tens and units digits for the minutes and the tens and units digits for the seconds.

In decimal, we need four bits to cover the all digits 0-9 in binary. So all the units columns on the LEDs have four LEDs. Because on a clock, none of the tens digits go all the way to 9, we don’t need a full 4 bits for each of the tens columns. Hours for example only go to 2, so we only need 2 bits for a 24 hour clock. The minutes and seconds only go to five so we only need three bits for those.

So, to make this, what are our requirements?

For the LEDs, we have 3 groups of 4 and 2 groups of 3 for a total of 18 and another 2 for a total of 20 LEDs that we need to control.

Second, we need a way of keeping track of the time.

Third, we need a way to set the time.

I’ll talk about all these requirements in detail but first I’m excited to announce that I’m working on some Arduino training materials. I have an Arduino reference poster available now and am working on a book for people new to digital electronics and programming the Arduino. A digital version of the poster is available by just signing up to the House of Hacks mailing list where I’ll keep you updated on things happening here. I won’t bombard your email with a bunch of stuff. Just occasional updates when products are released and an occasional news item that I think you might find interesting related to making things. If you’re interested in this, there’s a link below in the description below.

Now, back to the design...

Looking at controlling the LEDs, my first inclination was to think about this as a single string of 20 bits where each digit in each group was put inline with the rest of the bits. The common way of working with large numbers of LEDs is to use a '595 based shift register. This only requires three pins on the Arduino but provides a number of digital outputs. This is so commonly used that there’s a shiftOut command built into the Arduino ecosystem. ‘595 chips typically only work with 8 bits (although there are variants that have more bits) but they can be daisy chained together so you can have an almost arbitrary number of digital outputs, all controlled by only three pins.

Since there’s 20 bits needed and each ‘595 provides 8 bits, I thought about using three shift registers, daisy chained together. This would give 8 times 3, or 24, bits. The first 20 bits would be used and the last 4 bits would be ignored.

I coded up a prototype sketch using this idea but it ended up being more messy than I really liked. All the code was one big blob with a bunch of dependencies spread throughout the whole thing. Some of that mess could be cleaned up with some refactoring, but it was still going to be more messy than I really liked.

Upon reflection, I realized each group of two numbers only needs at most 7 bits and I have three groups. For the purposes of this project, I could still use the three ‘595s but instead of daisy chaining them together, I could connect each one to the Arduino directly. This would help make the code cleaner. Each ‘595 needs three pins, so that’d be a total of 9 pins for the LEDs instead of 3. Let’s look at the rest of the requirements and see if there are enough pins.

To track time, the most reliable would be to use a clock module. A real time clock module, also called an RTC, is designed to interface with micro controllers and has it’s own battery backup. There are a number of different models. I selected to use a DS1307 because they can be had inexpensively and communicate with the Arduino using only three pins over the I2C bus.

It would also be possible to use the Arduino itself to track the time although I’m not to sure how accurate that would be. It would provide a software only solution though.

Finally, we need a way to set the time.

The commercial unit I have uses two buttons. One increases the hour each time it’s pressed. The other increases the minute each time it’s pressed and if they’re both pressed at the same time, the seconds are increased.

This could work, but I don’t have any good buttons that’d be appropriate for mounting in an enclosure and, in my spare parts bin, I have a rotary encoder.

Rotary encoders come in different styles. This particular one allows the user to spin it in either direction without any limits. It can also be pressed to indicate an event. The micro controller can detect which direction it’s turned and take appropriate action.

I think this would be easier to make accessible to the user in the enclosure, so I’m going to use it. It uses two pins to the Arduino to communicate the rotary action and one pin to communicate being pressed.

So, all in all, I’m looking at using 9 pins for the three ‘595s, 2 pins for the clock module and 3 pins for the rotary encoder. A total of 14 pins.

Since I want to keep this pretty compact, I’m going to select the Arduino Micro. It’s only about 2 inches long and about 3/4 inch wide and designed to go in breadboards and pre-made circuit boards with standard hole spacing. And it has 18 digital I/O pins. Four more than then 14 that we need.

I think it should work well.

So, I’ll go order the parts and, while waiting for them, I'll show you the software in this video.

If that video hasn’t been released yet, I’ll see you in this other video where I do an Arduino project simulating wind to make wind chimes sound indoors.

After watching that, go make something.

Perfection isn't required. Fun is!

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!

Friday, March 22, 2019

How to Subtract In Binary Using 2'S Complement


Description

Interested in subtracting in binary using 2's complement? In this final episode in the Bits of Binary series, Harley begins with what we know about subtracting in decimal and applies that to binary. Along the way way he introduces 2's complement and shows how it makes subtracting binary numbers a matter of simple addition.

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 to Subtract In Binary Using 2'S Complement

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

Transcript

This is an elegant but non-intuitive way to represent negative numbers.

On this episode of Bits of Binary, I'll explain how it works, here at the House of Hacks.

Hi Makers, Builders and Do-It-Yourselfers. Harley here.

This is the last planned episode in the Bits of Binary series.

Previous episodes explored the concept of alternate number systems and how to do various mathematical operations in binary.

If you missed any of these episodes or want a refresher, they're all in this playlist.

In this past episode, I explained how to subtract a smaller number from a larger one.

It introduced subtraction and related it with how you know how to do it in decimal.

But by limiting the scope to smaller numbers subtracted from larger ones, I avoided the topic of how to deal with negative numbers.

Let's look at negative numbers and how computers represent them.

When learning decimal in grade school, we started with only positive numbers.

Once we got that under our belt, we were introduced to negative numbers, where the number line just mirrored the positive side with a negative sign in front of the number.

We could do the same thing with binary; just add a negative sign in front.

And if humans were the primary users of binary math, this would probably be sufficient, just like it is in decimal.

But we have to remember that the most common use of binary numbers is inside computers.

In the digital electronic environment of voltages, currents and electrons, we don't have the luxury of introducing another abstract symbol like a minus sign.

Ultimately, everything has to reduce to an on or off value.

Further, because of the physicality of the equipment, representing numbers of arbitrary length is hard.

So, two things are done to simplify the problem for computers to use.

First, there are already two symbols, 0 and 1 represented by no voltage and a voltage.

Rather than introducing a third symbol like a minus sign, a 1 is used to represent a minus and a 0 is used to represent a plus.

Second, instead of allowing an arbitrary number of digits, a fixed number of digits is defined.

Typically the number of digits are a power of two: 4, 8, 16 and so forth.

For the purposes of example, we'll assume 8 digits.

If we assume an unsigned number, 8 digits gives us a range of 0 to 255, or all zeros to all ones.

If we use a 1 in the most significant bit to represent a negative number and a 0 to represent a positive number, we reduce the number of bits for the number by one to 7.

This gives us a range of 0 to 127. With the last bit for a sign, the total range is 0 to +/- 127.

This introduces some interesting problems.

In this scenario, you have 0 to 127 in the positive range and then you add a 1 to the front for negative numbers.

Look what happens here at 0.

You have both a positive zero and a negative zero.

This doesn't make too much sense from a mathematical perspective.

The other problem is how to simply handle negative numbers?

First let's look at a decimal example to remember how borrowing works.

Let's take 2002 - 3.

We have 2 - 3, we can't do this so we try to borrow 1 from the previous column.

The previous column is already 0 so we have to borrow from its previous column.

Well this is also 0 so we do it again.

This means the two changes to a 1 and the third column is 10.

Now we borrow the 1 making the third column 9 and the second column 10.

Now we can borrow the original 1 we needed leaving the second column 9 and the first column 12.

Now the subtraction can occur with a final value of 1999.

Remember how this borrowing against 0 columns causes them to become 9s.

We'll come back to this.

Let's look at another example of 1 minus 2.

According to our earlier rule, we can't take a larger number from a smaller number.

So we make a new rule that says if we have a larger number from a smaller number, then swap the order and and add a minus sign to the result.

We could in theory do this in electronics.

Do a comparison, swap the order if needed and add the minus sign.

While it can be done, it's pretty complicated circuitry.

Let's look at what happens if we try doing some borrowing.

Using our example of 1 - 2, in binary we have 1 - 10, we can't do this so we have to borrow from a previous column.

But since the previous column is 0 so we go to the next column.

We do this until we run out of columns.

So we set the negative sign and make this last column 10, or the value 2.

Now we borrow one from that column, leaving 1 and shift to the next column.

This borrowing propagates all the way back leaving 1s in each column, just like we had 9s in our earlier decimal example.

Finally back to the first column, with the borrow, the subtraction can be done, leaving 1.

Because we have 0s in all the remaining columns, the borrows drop down, like the 9s did in our first decimal example.

This gives us a final value of 11111111.

If we wanted to make this look like the original idea of using the last bit for a sign and the remaining bits look just like their positive counterparts, somehow we need to make this look like 10000001.

We need to figure out how those 1s that are a result of borrowing get changed back to zeros.

It turns out this is a pretty complicated problem too.

But what happens if we just assign the result of all ones to mean -1?

Ultimately numbers are just arbitrary symbols with assigned values.

There's nothing stopping us from just saying this symbol represented by all 1s has the value -1.

If we do this, it really simplifies the electronic circuitry for the computer designers.

Let's take look at a couple other examples.

Let's take 1 - 3.

In binary this is 1 - 11.

Going through the process we used for 1 - 2, we end up with a final result of 11111110 which we assign the value of -2.

Now let's take 1 - 4. In binary this is 1 - 100.

Going through the process again, we end with a final result of 11111101 which we assign the meaning of -3.

Doing this again for 1 - 5 gives us 11111100 meaning -4.

Is there a pattern emerging?

If we change all the 1s to 0s and 0s to 1s we see this.

And this is the positive values offset by 1.

So there is a pattern and it's pretty logical.

And it turns out doing this offset by one and change of 0s to 1s and 1s to 0s is relatively easy to do in electronic circuitry.

It's called two's complement and has become the standard way of representing negative numbers.

Going back to our school days learning decimal numbers, once we learned about negative numbers, we then learned that all subtraction problems can be transformed into problems where we add the opposite.

So 2 - 1 becomes 2 + -1 and 1 - 2 becomes 1 + -2.

Well the same thing happens in binary using two's complement notation for negative numbers.

2 - 1 becomes 2 + -1.

Working through this, 0 + 1 is 1.

1 + 1 is 0 carrying a 1.

This 1 + 1 continues until we run out of digits leaving us with 00000001, the expected answer.

If we switch the operands, we have 1 - 2.

Converting this to adding the opposite gives us this.

Working through this 1 + 0 is 1.

The remaining columns are all 0 + 1 giving us 1s for a final result of 11111111 or -1.

Again the expected answer.

And it turns out this works for any combination of numbers.

Let's look at this on a number line.

And remember that weird case we had before with a positive zero and negative zero?

Well, it turns out with two's complement math, what used to be that hard to deal with negative zero just becomes -128.

Here at House of Hacks, I hope to inspire, educate and encourage people with a bent towards making technical and mechanical things out of wood, metal, cameras and electronics.

Binary is the basis for many things related to digital electronics, as well as Boolean algebra, which I'll cover in a future series.

If topics such as these are interesting to you, be sure to subscribe and click the bell notification icon to have YouTube alert you when future videos are uploaded.

Thanks for joining me on our creative journey.

Until next time, go make something. Perfection's not required. Fun is!

Saturday, January 20, 2018

Binary number division: how to divide binary numbers simply


Description

Binary number division is simple and easy! In this short episode of House of Hacks, Harley shows how to divide binary numbers. This is one in the Bits of Binary series on binary arithmetic.

Are you interested in making things around the home and shop? You’ve found the right place. Here at the House of Hacks, we do tutorials, project overviews, tool reviews and more. Generally this involves wood and metal working, electronics, photography and other similar things. If this sounds interesting to you, go subscribe and click the bell to get notifications.

Multiplying binary numbers
Bits of Binary playlist

There's a playlist containing videos talking about the House of Hacks' values.

And here’s the most recent video.

For a written transcript, go to Binary number division: how to divide binary numbers simply

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

Transcript

In this previous video, we saw how multiplying binary numbers is almost trivial compared to multiplying decimal numbers.

In this episode of the House of Hacks, I'll show how division is just as easy!

[Intro]

Hi Makers, Builders and Do-it-yourselfers. Harley here.

Here at House of Hacks I hope to inspire, educate and encourage people who like to make things with a mechanical or technical bent to them.

Binary numbers are the foundation of much of our modern world and fall into the technical side of things.

This is one in an introductory series on binary numbers where I talk about how to read them, count in them and do basic math operations on them.

In this video we're going to be looking at division.

First a refresher for terminology.

Division involves dividing a dividend by the divisor and getting a quotient.

Remember in grade school how we had to memorize this multiplication table to know how to multiply and divide decimal numbers?

And remember how in the last episode we found out binary number multiplication was just these four elements of that table and how that made multiplication really easy?

Well the same thing holds true for division.

Let's get into this with some examples.

We'll start with 21 divided by 7.

Written as long division that looks like this.

Because our multiplication table only has two result values, one number can only be divided by another one 0 or 1 times.

This means a simple size comparison is really all that we need to look at when calculating the quotient.

Working through this, 111 is obviously larger than 1 so we start with 0.

111 is larger than 10, so we write down another 0.

111 is larger than 101. And again we write down 0.

Finally, 111 is less than 1010, so we write a 1 in the quotient, put the 111 under the 1010 and subtract.

The subtraction result is 11. Now we bring down the other 1.

And 111 is equal to 111 so we write a 1 in the quotient, put the 111 under the 111 and subtract.

Of course this is zero and we're done.

The resulting quotient is 11 which is three.

We know 3 times 7 is 21, confirming that the process works.

Let look at another example of 1011 divided by 10.

10 is greater than 1, so we start with a 0.

10 is equal to 10, so we put 1 in the quotient and 10 underneath and subtract giving us 0.

We bring down the 1 from the dividend.

10 is greater than 1, so we put a 0 in the quotient and we bring down the next 1.

11 is greater than 10, so we put a 1 in the quotient and 10 underneath, subtract, giving us 1.

There's nothing left of the dividend to bring down so we have a couple options that are the same as we have with decimal remainders.

We can either write the remainder as part of the quotient.

Or we can write the remainder as a binary fraction.

Or we can place a radix point and continue the division.

If we do this, we place a dot in the quotient and bring down a 0 next to our remainder giving us 10.

10 is equal to 10 so we place a 1 in the quotient and subtract the dividend from the working value.

The result is zero and we're done.

If the result was greater than zero, we'd bring down another 0 and continue expanding the radix part of the quotient, just like we do when working in decimal.

In the next episode of Bits of Binary, we'll take another look at subtraction by introducing negative numbers.

If you're interested in making things with a mechanical or technical bent to them, consider subscribing for future videos showing DIY projects, home and shop tutorials and other things related to wood working, metal working, photography, electronics and similar materials.

Thanks for joining me on our creative journey.

Now, go make something. Perfection's not required. Fun is!

Sunday, October 29, 2017

How to multiply binary numbers


Description

Continuing the Bits of Binary series, this episode of House of Hacks shows how to multiple binary numbers. Harley shows how binary number multiplication is as easy as 1 x 1 = 1 and 1 x 0 = 0.

This is the fifth in a series dealing with binary numbers. All the videos in this series can be found on the Bits of Binary playlist.

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 on YouTube.

Here’s the most recent video.

For a written transcript, go to How to multiply binary numbers

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

Transcript

Do you want to multiply binary numbers together?

In this episode of the House of Hacks, we'll look at how easy this operation really is.

Hi Makers, Builders and Do-It-Yourselfers. Harley here.

The playlist up here contains previous episodes where we looked at what binary numbers are, how to count in binary, how to convert between the more familiar decimal base 10 numbers and binary, and how to do addition and subtraction on binary numbers.

In this episode we'll look at multiplying binary numbers together.

Back when we learned how to multiply decimal numbers in school, we had to memorize a table that looked something like this.

If you know this table, you already know everything there is to know about multiplying binary numbers.

The cool thing is multiplication in binary is exactly the same as decimal except you only use these two rows and columns from the table you've already learned.

And the process is exactly the same too.

Let's take a look at a couple examples and then a couple short cuts.

Let's take seven times three.

Just like in decimal, we first multiply the units and write that down under the equal bar.

Since we're multiplying by 1, we just write down the first number.

Then we add a zero placeholder and multiply by the next column.

Since we're again multiplying by 1, we write down the first number again.

And finally we add the two numbers together to get the total.

1 and 0 is 1.

1 and 1 is two, which in binary is one zero, so we write the 0 and carry the 1.

1 plus 1 plus 1 is three represented in binary as one one, so write the 1 and carry the 1.

Again, 1 plus 1 is 10 so write the 0 and carry the 1.

1 and 0 is again 1 so write the 1 and we're done.

Let's double check this by converting the result to decimal.

Remember each column is a power of two and we add the column values that contain a one.

Looking at the values of the columns we have 16 plus 4 plus 1 which is 21.

Let's do another one. Five times five.

Starting with the units, we multiply by the first number times one and write that down.

We put down a zero placeholder for the next column but notice we're now multiplying by zero.

So we ignore that column since zero times anything is zero, and add another placeholder and move to the next column.

We're again multiplying the first number times one and write it down.

Now we're ready to add.

One and zero is one.

Zero and zero is zero.

One and one is two, so write down the zero and carry the one.

One and zero is one.

Finally zero and one is one.

Giving us the result 11001.

Again, we can verify this by converting to decimal.

So we have sixteen plus eight plus one giving us 25.

There are two shortcuts we can observe.

First, since we're always multiplying by either zero or one, the numbers we're adding together are always nothing for zero or the first number shifted by the column that contains a one in the second number.

So this is a really mechanical process of just writing down the first number multiple times shifted as needed and then adding the numbers together.

As an example, we'll take this random number and multiply it by this random number.

We write down the first number with the units under the second number where the columns contain ones.

We can add placeholder zeros if it makes it easier to keep track of the columns.

And then just add.

The second shortcut is related to multiplying by powers of two.

Let's go back to decimal for a minute.

You probably know the shortcut for multiplying by a power of ten.

For ten, one hundred, one thousand, and so forth, all we have to do is add the appropriate number of zeros to the number we're multiplying.

Three times ten is thirty.

Three times a hundred is three hundred, and so forth.

Binary has a similar concept except it's related to powers of two: two, four, eight, sixteen and so on.

Every time a zero is added to the end of a number, it's the same thing as multiplying by two.

So if we are multiplying by two, we add one zero.

If we're multiplying by four we add two zeros, and so forth.

And since powers of two in binary look just like powers of ten in decimal, we really don't have to think about it.

All we have to do is add zeros and we're done.

In this episode, we looked at how binary multiplication is using all the same ideas as decimal multiplication we're already familiar with.

We also looked at two easy shortcuts to mechanically handle the multiplication and multiplying by powers of two.

Binary is a common non-decimal numeric base, but really, any number can be used as a base for a number system.

Leave a comment below if you've worked with number bases besides decimal and for what purposes.

If this is your first time here at House of Hacks: Welcome, I'm glad you're here and I'd love to have you subscribe.

Through these videos I hope to inspire, educate and encourage makers in their creative endeavors.

In spite of this series, usually this involves various physical media like wood, metal, electronics, photographs and other similar materials.

So subscribe and I'll see you again in the next video.

Thanks for joining me on our creative journey.

Now, go make something.

Perfection's not required.

Fun is!

Sunday, April 5, 2015

Bits of Binary: How to subtract binary numbers



Description

Subtraction can be done two ways using binary numbers. This episode talks about unsigned subtraction, very similar to how we do it in decimal notation. We'll dive into the details in this episode of Bits of Binary at the House of Hacks.

Links

Bits of binary playlist
What is binary?
How to count in binary
How to convert between binary and decimal
How to add binary numbers

For a written transcript, go to How to subtract binary numbers.

Credits

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

Transcript

That may look confusing on the surface, but if you saw the last Bits of Binary episode, it might make some sense. I'll explain it in more detail in this episode of the House of Hacks.

Hi Makers, Builders and Do-It-Yourselfers. Harley here.

This is a continuation in the series on Bits of Binary. In previous episodes I explored the concept of binary numbers, how to count in binary, how to convert between binary and decimal and, in the last episode, I showed how to add binary numbers together. In this episode, I'll show the simple, obvious way to subtract them that's analogous to how we first learned it in decimal. In a future episode I plan to introduce the non-intuitive way negative numbers are stored in computers and how that impacts subtracting binary numbers.

Remember last time when we talked about addition, we looked at these two tables...

Let's remember how we use this with decimal numbers. We'll ignore negative numbers for now so we'll establish the rule that the first number has to be larger than the second. Since this half of the table is the same as this half, we’ll just ignore one side.

When describing the process, we'll use the example 8 - 5.

The process is to first find the entries in the table for the first number. Then, of those entries, you find the one with the other number in the header. The answer is the other header value.

Binary is exactly the same way, just with the much smaller table. Or written as a series of equations, it looks like this.

The first three probably make intuitive sense as they are the same as decimal. But the last one may not be quite so obvious. Remember that in binary the value for two is represented by 1, 0.

If we recall from grade school, with multi-column numbers, when we subtract a larger number from a smaller one, we have to borrow from the next higher column. Let's take for example 21 - 13 in decimal. The units column is 1 - 3. Well, we can't do that, so we borrow a one from the 2 in the second column giving us 11 - 3. This gives us 8. Moving to the next column we now have 1 - 1, giving us 0.

Binary works exactly the same way. Let's look at some examples in binary.

First something simple: 6 - 2. The units column is 0 - 0 equals 0. The next column is 1 - 1 equals 0 again. The final column is 1 - 0, giving us 1. This gives us an overall result of 100, or the value 4.

Now let's do something with some borrowing: 6 - 3. The units column is 0 - 1. We can't do that so we're going to borrow a 1 from the next column. Now we have 10 - 1 giving a result of 1. Because of the previous borrow, the second column is 0 - 1. So again we borrow from the next higher column giving us 10 - 1 with a result of 1. The final column is 0 (because of the previous borrow) - 0 giving us 0. Overall, the result is 11, or a value of three.

And that's it. Subtraction is a bit more complicated due to the borrowing, but again, it's a known concept just applied in a slightly different way.

Thanks for watching this episode of Bits of Binary. As I mentioned earlier, a future episode will explain how negative numbers are handled in a computer and a less-intuitive but ultimately easier way to handle subtraction. But in the next episode, I'll look at multiplying binary numbers together.

I've created a playlist over here that will be filled in as more episodes in this series are added.

If you liked this, let me know with a "thumbs up.".

If you have any thoughts or questions on this topic, I'd love to hear them in the comments below.

If you're already a subscriber, "thank you!" and if you haven't done so already, be sure to "subscribe" so you don't miss future on topics such as this one, high-speed photography, making a digital computer with 19th century technology and much more.

Until next time, go make something. It doesn't have to be perfect, just have fun.

Wednesday, November 26, 2014

Bits of Binary: How to add binary numbers



Description

Addition is probably one of the most common operations when using binary numbers. And it's really easy to do. We'll see how easy in this episode of Bits of Binary at the House of Hacks.

How to convert between decimal and binary.
Bits of binary playlist

For a written transcript, go to How to add binary numbers.

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

Transcript

One plus one equals... huh? I'll talk about how this actually makes sense, today at the House of Hacks.

[Introduction]

Hi Makers, Builders and Do-It-Yourselfers. Harley here.

In the last episode of Bits of Binary, I showed how to convert between decimal and binary numbers. In this episode in the series, we'll look at how to add binary numbers together.

Remember in grade school when you had to memorize this addition chart?

Well, OK, maybe you didn't have to memorize it, but I sure did.

This table is a matrix with the 10 numbers found in the decimal system, 0 through 9, on both the row and column headers. Each cell contains the sum of its row and column header. This gives us the sums for all the single digit combinations. 0+0=0 all the way up to 9+9=18. Multi-digit numbers can be added by simply thinking of them as multiple single digit combinations.

Well, binary has something similar, but much, much smaller. Since there are only two numbers in the binary system, 0 and 1, the table only has two rows and two columns. And it looks like this.

Or if you want to write it a slightly different way as equations, it looks like this.

Once you know this table, the process of adding in binary is exactly the same as adding in decimal. For example let's look at the decimal numbers: 321 + 181. Staring with the units: 1+1 = 2, 2+8 = 10 so write 0 and carry a 1, 1 + 3 = 4 + 1 = 5.

Similarly, in binary we'll look at 1011 + 10. Starting with the units on the right: 1 + 0 = 1, 1 + 1 = 10 so write 0 and carry a 1, 1 + 0 = 1, 1 + 0 = 1 again.

That's it. Addition is short and sweet. Thanks for watching this episode of Bits of Binary. In the next episode, we'll look at how to subtract binary numbers.

I've created a playlist over here that will be filled in as new episodes in this series are added.

Thanks to everyone who has subscribed to this channel and liked the videos.

Be sure to leave a comment if you have any thoughts or questions on this topic.

And until next time, go make something. It doesn't have to be perfect, just have fun!

Thursday, July 10, 2014

Bits of Binary: How to convert between binary and decimal


Description
Learn how to convert from binary to decimal numbers and from decimal to binary numbers.

There's a written transcript for How to convert between binary and decimal.

There's also a playlist for all the Bits of Binary episodes.

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

Transcript

If you don't get this classic joke, by the end of this episode you should. Today I explain how to convert binary to decimal, and back again, here at the House of Hacks.

Hi Makers, Builders and Do-It-Yourselfers. Harley here.

In the last two episode of Bits of Binary, I introduced alternate number systems in general and the binary system in particular. Next I showed how you can use binary to count much higher than ten on just your fingers. I closed with the question "How high can you count in binary on both hands?" If you came up with the answer 1023, you really understand the basics.

In this episode in the series, I'm going to show how to convert from binary to decimal and from decimal to binary.

Last time, I explained how each column in a number is the base number raised to a power times the value of the column. That sounds more complicated than it is. In our familiar base 10, or decimal, system, the columns are 10^0, 10^1, 10^2 and so forth. This gives us columns that represent units, tens, hundreds and so on. To get a specific number, say 123, you simply multiply the number in the column by the column's value. Or (100 * 1) + (10 * 2) + (1 * 3). Applying this principal to binary, the columns are 2^0, 2^1, 2^2 and so forth. Giving us 1, 2, 4, 8 and on up.

So, let's convert from binary to decimal. What's the decimal value of the number 10101? Given that each column represents a power of two and each column can only have a value of 0 or 1, this means its value is (2^4 * 1) + (2^3 * 0) + (2^2 * 1) + (2^1 * 0) + (2^0 * 1). Removing the items multiplied by zero gives us (2^4 * 1) + (2^2 * 1) + (2^0 * 1). Evaluating the exponents gives us (16 * 1) + (4 * 1) + (1 * 1). And all this simplifies to 16 + 4 + 1 or 21 in decimal.

Now that we know the theory, let's look at some shortcuts. Instead of looking at the columns as 2 to a power, we can look at them with specific values. Starting with the units column, we know it's one. Each subsequent column is the current column times 2. This gives us 1, 1 * 2 is 2, 2 * 2 is 4, 4 * 2 is 8, 8 * 2 is 16 and so on. Next, all we need to do is write the binary number below the numbers: 10101. And then simply add the values of the columns with 1's in them. 16 + 4 + 1 = 21 decimal.

Binary to decimal is really pretty simple.

Next, let's convert from decimal to binary. This is slightly more complicated, but still not hard.

We need to start with a binary column value larger than our decimal number. So, we start at the right side with one and multiply by two until we have a number larger than what we want to convert. Then working from the left we apply this rule: if the value we want to convert is greater than or equal to the column value, then we set a one for that column and subtract the column's value, otherwise, we set a 0 for that column and continue. The result is then applied to the next column. And we apply the rule until we reach zero.

Let's try the earlier example of 21 decimal. First, find the columns. Start with 1 and double until we have a value greater than 21. Then start from the left and apply the rule. 21 is less than 32 so we write a 0 and move to the next column. 21 is greater than 16, so we write a one below the 16 and subtract 16 from 21 leaving us 5. Next column. Five is less than 8 so we write a zero below 8 and move on. Five is greater than 4 so we set a one below the four and subtract four from 5 leaving us 1. One is less than 2 so we set a zero below the 2 and move to the units. One is equal to one so we set a 1 in the units column, subtract 1 from one leaving us zero and we're done.

If we get to the end without reaching zero, we've done something wrong and need to recheck our work.

Looking at the binary value, we have 10101, which is what we saw in the previous example of binary to decimal, so it all works.

Let's try 24 decimal as another example. 24 is greater than 16, so we set a one below the 16, subtract 16 from 24 leaving us 8. 8 is equal to 8 so set a one below the 8 and subtract 8, leaving us 0. Since we know 0 is less than all the other columns, we can just set them to 0 and be done. This leaves us 11000 binary.

That's all there is to convert between binary and decimal.

I've created a playlist over here that contains all the episodes in this series so far and will be filled in as more are added.

Thanks for watching and if you learned something, I'd appreciate a thumbs up If you have any questions or comments, leave them below. I try to respond to all of them.

So until next time, go make something. It doesn't have to be perfect, just have fun!

Tuesday, April 8, 2014

Bits of Binary: How to count in binary


Description

For a written transcript, go to How to count in binary

Music under Creative Commons License By Attribution 3.0.
Intro/Exit: "Hot Swing" by Kevin MacLeod at http://incompetech.com
Incidental: "Feelin Good" and "Cold Funk" by Kevin MacLeod at http://incompetech.com

Transcript

If you recognize this as the number 31, you can skip this video. But if you want to know how to count to 1023 on just your fingers, we'll find out in this episode of the House of Hacks.

Hi Makers, Builders and Do-It-Yourselfers. Harley here.

In the last episode of Bits of Binary, I talked a bit about different binary systems in general and binary numbers in particular. You can click here if you're interested in this introduction.

In this episode, I'll start with the basics of decimal numbers that you may already know. I'll then relate that to alternate number systems in general and then binary numbers specifically. Finally I'll wrap up with how to count in binary.

When we were young, we learned to count on our fingers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.

A couple years later we learned there's actually a special value that's no quantity: 0. And and with this new knowledge we found that 10 really isn't a number in the same way as the other nine are. It's a combination of 1 and this new non-value value. We found that at the core, we have 0 through 9 as our ten digits, not 1 to 10.

While were were still reeling from this new information, we learned you can count the groups of 0 through 9 and keep track of that in the "ten's column." So, now we could have 10 through 19 and 20 through 29 all the way up to 90 through 99. And then we could add a "hundreds column" for 100 through 199 and so forth. Numbers could actually be arbitrarily large by just adding another column.

This was mind blowing!

There were numbers incomprehensibly large to our young minds like "million" and "billion" with all kinds of crazy numbers of columns.

Then as we grew and got more sophisticated, we learned about something called exponents. These columns we were so comfortable with could now be represented by 10 raised to number of the column. So the "ten's column" was 10^1 and the "hundred's column" was 10^2. The "unit's column" took advantage of a weird property of exponents that said "anything raised to the power of 0 is 1."

It was explained any number could be split into its constituent parts by taking the digit in each column and multiplying it by the power of 10 for that column and adding the results together for the other columns. We found the simple columns we learned early in our education were just shorthand for much more heady concepts.

For example, the number 123 could be written (1 x 10^2) + (2 x 10^1) + (3 x 10^0).

If you're anything like me, this is about where the educational system stopped. There was no direct talk about this "5" being an abstract symbol for an underlying value. They did talk about it in an oblique way when they talked about other cultures having other number systems such as Roman numerals I, V, X, L and C. But that was about it. It was simply given that "5" meant "*****" this many things.

This was the decimal number system and how those of us now middle aged in the United States probably learned it.

If you had your young mind blown when you learned the ten's column was 10 raised to 1 and the hundred's column was 10 raised to 2, here's another mind blowing revelation...

The column base, the 10 so far, doesn't have to be limited to the number 10. It can be any anything!!

For example, this base could be 16 where you'd have the familiar zero and 15 other symbols. In this base, this many objects "**** **** **** ****" would be written as 10. Even though it looks like ten, it isn't. It's sixteen. And if you add one more "*", it'd be written 11 meaning seventeen.

Or the base could be 8 where you'd have zero and 7 other symbols. In this case the quantity seventeen would be represented by the series of digits 21. But in decimal, it'd still be represented by 17 and in base 16 it'd still be 11.

When dealing with multiple number systems at the same time, typically we put a subscript after the number to indicate the base for that number. So in the example of seventeen items, the previous bases would be written as 11(16), 21(8) and 17(10). This helps reduce confusion. But typically only one system is used at a time, and the base is left off, since it's implied by the context.

As you're trying to get your brain around all this, let's talk specifically about today's topic: binary. Its base is 2 so all we have is zero and one other digit: 1. That's it. 0 and 1, 1 and 0. Easy!

Let's look again at the columns we learned about when we learned about exponents. Just like in decimal where column one was 10 to the 0 and column two was 10 to the 1 and column three was 10 to the 2 and so on, in binary column one is 2 to the 0 and column two is 2 to the 1 and column three is 2 to the 2. That means the value of these columns if we multiply them by 1, are 1, 10 and 100 for decimal. And for binary they are 1, 2, 4, 8 and so forth.

Going back to our earlier example, in decimal, for each column's power of ten, you can multiply it by a number from 0 to 9, because your base is 10.

Binary however is much easier. For each column's power of two, you can only multiply it by either 0 or 1, because that's all the digits we have.

So, let's see what happens when we count from 0 to 10. For comparison, let's see both decimal and binary side by side. 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

See this pattern...

If we use a finger to indicate one and apply this pattern to our fingers...

zero, one, two, three, eight, nine, ten.

By continuing this pattern, on one hand we can count to the number 31. This is 16. Plus 8. Plus 4. Plus 2. Plus 1. That totals 31. So, how high can you count using both hands?

Thanks for watching this episode of Bits of Binary. In the next episode, we're going to look at how to convert back and forth between binary and the more familiar decimal numbers.

And I've created a playlist over here that will be filled in as more episodes in this series are added.

If you liked this, let me know by hitting the "like" button.

If you are already a subscriber, "thank you!" but if you aren't, be sure to "subscribe" so you don't miss future videos.

I'd love to hear from you in the comments below if you have any thoughts or questions on this topic.

Until next time, go make something. It doesn't have to be perfect, just have fun!

Tuesday, February 11, 2014

Bits of Binary: What is binary?


Description
What do Morse code, Braille and binary numbers have in common? Find out in this introductory episode of the new Bits of Binary series.

Bits of Binary playlist

For a written transcript, see House of Hacks.

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

Photos in public domain:
Transcript

What do Morse Code, Braille and binary numbers have in common? Let's find out today at the House of Hacks.

Hi Makers, Builders and Do-It-Yourselfers. Harley here.

As I think about different videos I want to do in the future, certain areas of knowledge seem to recur. They're somewhat foundational. I plan on doing a couple series on these foundational topics. But don't worry. I'm not going to do them exclusively. I'll intersperse them with my normal projects and other tutorials. This is the first episode in the first of these series. And now, to the topic at hand.

Morse code uses short signals called dits and long signals called dahs in various combinations to encode letters, numbers and other symbols. The dits and the dahs can be represented by long and short sounds, or blinking lights or any other method of indicating two states.

For example, this is the letter "A." And this is the letter "B." And here's "Hello world."

The interesting thing here is there are two things, a dit and a dah, in the context of silence to separate letters and words to communicate.

Braille uses a two by three grid containing various patters of raised to encode letters, numbers and other symbols.

For example, this is the letter "A." And here's the letter "B." And here's "Hello world."

Braille is used predominately to allow blind people to communicate in written form. Interestingly, it was adapted from a similar system used by the French military to communicate on the battlefield without using sound or light that might give away their position to the enemy. So, it doesn't have to be used exclusively by the vision impaired. But that's a bit of a historical side note.

The important thing for the purpose of this discussion is to note it uses either the presence or the absence of a raised dot. A bit of information, in the context of other bits of information, the two by three grid, to convey more information.

Binary number systems use just zero and one to represent numbers.

For example, this means one. And this means two. And this means ten.

Computers use either the presence or absence of a voltage to indicate either zero or one. And they build sequences of these up into numbers to represent symbols, numbers and letters.

So, what is binary?

Simply, binary is defined as something having two parts. Each of these systems we've talked about today use just two things, within a context, to encode information. Morse code uses sequences of dit and dah. Braille uses the absence or the presence of a dot within a grid. And binary numbers use zero and one within a sequence.

In future episodes in this series, I'll be discussing binary numbers in more depth. How to correlate them to the decimal system you're probably already familiar with and how to perform mathematical operations on them.

There's a playlist over here that will have new episodes added to it.

And finally "Thank you" if you've already subscribed. You can configure YouTube to notify you when new episodes are available. If you aren't subscribed and you want to get those notifications, be sure to subscribe. It's free and contains zero calories. Finally, if you're interested in this series, go ahead and hit the "like" button, that'll let me know there's interest in this.

Thanks for watching and until next time, go make something. It doesn't have to be perfect, just have fun.