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

Monday, November 9, 2020

Labists Starter Kit For Raspberry Pi 4: Everything you need to know

Description

Interested in a Labists Starter Kit For Raspberry Pi 4? In this episode, Harley unboxes, assembles and runs through the initial setup wizards for one of these kits.

Sign up for book updates: https://list-optin.house-of-hacks.com/
The kit I got: https://amzn.to/3oYXY45 (Affiliate link)
A list of different kits: https://amzn.to/2TZj187 (Affiliate link)

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 Labists Starter Kit for Raspberry Pi 4.

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"

Contents

Transcript

Introduction

Today at the House of Hacks we're going to unbox and setup this Labists Raspberry Pi Starter Kit.

OK, the box it comes in is nice and sturdy, not much to it.

Just kind of your basic box.

We're going to go ahead and open this up.

It's got a couple anti-tamper stickers on it.

And we'll just open this up.

Recently I've had some ideas floating around my head for some projects where it needed a little bit more computing power than what an Arduino supplies but I still wanted to be fairly close to the hardware.

So, of course the Raspberry Pi is a great solution for this.

Having never worked with Raspberry Pis before I didn't have anything and I wanted a starter kit to just get going quickly.

So, I searched on Amazon and found this Labists Starter Kit. It came with pretty high reviews and seemed to be pretty complete. So I went ahead and got one.

It's supposed to have a case and power supply and other miscellaneous things that you need to get started.

It doesn't have a keyboard or monitor, of course, but I have those in plenty.

I went ahead and got one of these. It has 8 GB of RAM and 128 GB SD card and so I thought I'd open this up and show you what it takes to get started.

If we're just meeting, I'm Harley. Welcome. This is the House of Hacks where I make stuff.

Usually out of metal or wood, other kinds of media like that. Sometimes it includes things like Arduinos and Raspberry Pis.

Unboxing

It starts off with a Raspberry Pi Model B. 8 gig of RAM.

That looks like the main box or the main computer.

I have to rip the box and there's the Pi.

They are pretty small little units, aren't they?

It has the connectors on the side. The power supply.

Network. USB. Looks like USB 2 and 3.

And yeah, there's not much to it. Not much bigger than an Arduino.

Just for size comparisons, there's an Arduino Uno.

It's a little bit bigger but about the same size.

Digging more into the box...

Packing material.

Oh, and inside this box looks like there's some basic instructions and a fairly large piece of paper with multiple language instructions.

We've got a Quick Start Guide.

A power supply... with an on/off switch.

Labists power supply.

We have, looks like a case.

I assume it snaps open somehow. I won't do that on camera but it's got holes for the connectors.

It must go this way. There's the connectors that way and that way.

And interestingly, it looks like it has a 1/4-20 connector on there which I'm guessing they may have it setup for putting a camera on this. That kind of looks like a camera hole. I don't know exactly.

That looks like a hole for a lens on a camera. They might have an aboard board camera you could put on there and then that would be for taking pictures with.

Interesting little concept.

HDMI cable.

This looks like another HDMI cable.

That's definitely HDMI... and that's definitely HDMI.

So, two HDMI cables.

A cute little tiny fan.

I assume that goes in the case.

An SD card that says Raspbian on it. So, I assume it's preloaded with the operating system. That's handy.

I don't recognize that.

I'll have to read the manual for that one.

A little screwdriver for mounting the fan.

Some heat sinks.

And that's it.

So, everything that comes in the box.

Those are the things that are inside the box in this kit. I want to get into the setup of this and see what happens when we turn it on for the first time but before that I do have an exciting announcement.

Those are you that have been around the channel for awhile may have noticed that my uploads this year have been down from previous years.

That's not because I've been slacking off but because I've been working on a new project.

This is a beginner's guide to working with electronics, specifically the Arduino ecosystem.

So, if you've been interested in getting Arduinos into your projects but don't know anywhere to begin, this book is for you.

I talk about three things in it...

Basic electronics. What is a transistor. What is a resistor. Real basic things like that.

And then I talk about how to setup a computer to program an Arduino.

And third, I talk about the basic elements of what goes into an Arduino program and the fundamental programming issues related to that.

If this is something that's interesting to you, I've left a link down below for a mailing list where I'll be announcing when the book is released and also providing a discount code for those that are interested.

Assembly

Now that we've got everything unpacked, let's assemble this.

The Quick Start Guide is fairly thick and a bit intimidating at first glance but there's six languages in here so for any one language there's only about four pages.

Half of those four pages are how to install the operating system on a blank SD card.

The SD card that comes with this is already pre-formatted so we don't need to worry about those two pages.

About half of the rest is specifications and what comes in the kit.

So there's really about a page, page and a half, of actual instructions for getting started and those seem to be really clear in reading things over.

I don't have any questions off the top of my head.

We'll see how complete they are once we get into it and see if we have any questions.

The mystery piece that I wasn't sure when I was unboxing it is actually an SD card reader which is kind of handy.

It's a type C connector. It pulls apart and there's the connector for plugging into USB and there's where the SD card goes in on the back side.

So that's kind of cute. It's an inexpensive one. It's not great but I'm sure it works for the purposes that we have here today.

There's really only a couple steps we need to do.

We need to install the heat sinks onto the card.

We need to install the fan into the case.

And then we need to install the card into the case and put it all together.

Finally we can install the SD card after the card is in the case and then apply power and keyboard and monitor and see how it works.

They do say that you don't want to have the SD card in the computer when you're trying to put it in the case.

I think there's a fitment problem trying to get it all lined up and stuff.

So you put the card in after everything is assembled and put together.

So, let's get to this.

First we're going to put the heat sinks on the chips and the manual says exactly which ones they go onto and they are self adhesive so they should go on fairly easily.

We've got this one goes on that chip.

We've got this square one that goes on the main CPU.

And then we have this other smaller one that goes on, looks like the chip that's right there.

So that's how it's assembled.

Time to get out the tools.

I've got a pick that works really well for taking off things like self-adhesive tape when it's hard to get off.

That one wasn't too bad.

So that goes on... try to get my fat fingers in here on this little board. That goes on that chip.

Just press it on.

This self-adhesive tape isn't too bad to take apart. Sometimes it can be a real pain.

That does on that chip.

And this goes on the last one.

I assume that is the primary CPU. It's this metal cased one.

That was easily done and I didn't need the pick at all.

So now we want to install things in the case.

The case just pulls apart. There's a little handle there.

And there's screws for mounting the board and there's screws for mounting the fan.

It seems that there's more screws there than I actually need.

And this case also is designed for a camera. I didn't get the camera option but there is a hole in the case and mounting space to snap a camera in there.

The fan can go in two ways. There's no indication of air flow.

I don't know that it really makes a difference which way it goes in.

I'll put it in this way so the strain relief on the cable pulls up.

The self tapping screws go into the fan. They have a round head on the top.

They're a bit longer than the screws in the other package that are for the card.

You don't want to torque them down too tight since you may strip out the plastic.

You just need to make them so it holds things in without rattling.

And that's the fan in there.

Next we need to mount the board.

It's pretty obvious. There's big holes in the case go for the USB and ethernet port.

And this should just drop in there.

And there are...

It seems to fit... fairly snugly.

There we go. You can kind of feel it where it snaps in.

You want to make sure the connectors are all lined up with the holes and the connectors on the side actually fit into the holes on here so there's a bit of a snap feel to it.

Get the other screws.

These screws I'm going to need the spectacles for.

It'd be nice if this screw driver was magnetic but that one went in without too much difficulty.

On screws like this, I tend to start them, get them all started, and then I go through later and with a second pass tighten them down for good.

That way you don't... If you tighten it down one at a time, sometimes you'll knock things out of alignment and then it's harder to get the other screws in.

And for both sets of screws, they sent me one screw more than I actually needed. Which was convenient since I dropped of those on the floor. I'll have to go retrieve that later.

And then I can go through a second time and tighten everything down.

Again, you don't want to tighten it down too tight because you don't want to strip the threads or the head.

And this screwdriver seems to be possibly at end of days.

This one screw... No this one screw has some munged up threads.

The screwdriver is fine. The head is rounded out without putting any torque on that at all.

And I can't get it out so now I need to get the pliers.

Let's try the extra screw that they gave me.

Those are magnetized and it's making it hard to get the screw in.

Once you have threads in plastic you want to do a technique called indexing where you turn backwards until you feel a click and then you can go forwards again.

That way you're not cutting new threads into the plastic.

And this new new screw worked much better.

There we go.

So I think now we are ready to put the operating system SD card into the case.

There's a small slot right there on the back of the case that this should slide into just like so.

And yeah, it protrudes out so if that was in the card when we tried to put the card in here, we'd have problems getting it in. So that's definitely what's going on there.

Now we're ready to wire up the fan.

The fan goes in this way and there's two options on this.

The red wire is positive and the black wire is negative and the manual says which ones go where with some pretty detailed instructions.

There are two options on this fan. You can either run it at low speed on 3.3 volts or at high speed on 5 volts, both of which are available right here on the GPIO connector.

And the black one is ground and it's on pin 6 which it shows right there.

I'll orient this in the way it shows in the diagram. Pin 6 is the third one on the top. So it goes in there.

And then the red is either pin 1 for 3.3 volts or pin 2 for 5 volts.

So I'm going to put it on 5 volts because, hey, more power! Right?

And then everything should just snap together if I can figure out which way this goes on.

And there we have it. We're ready for power, keyboard and video.

Setup

So, we have the things that came with the kit and a few extra items in order to use this.

We need an external monitor. This is a small HDMI monitor that is designed for use with video equipment but any HDMI output source will work.

I also have a keyboard and mouse. Those are really the only things you need in addition to what comes in the kit.

For the purposes of today and this particular setup, I also have an HDMI splitter so that I can run the signal out of the Raspberry Pi, not only to the monitor, but also into my computer to be able to record it and capture it in high quality so that you can see what's going on in the video.

That complicates this particular setup but that's not a setup that you'd normally need when working with the Raspberry Pi.

One thing of note, is while the power supply that comes with a Pi looks like a normal wall wart, it is a high power device.

The Pi requires more than what most wall warts produce.

Most wall warts output in the milliamp to maybe 1.5 amp range.

The Pi needs more than that and this particular one that came with this kit is a 3000 milliamp, or 3 amp, power supply.

So, you do want to make sure that if you're not using a kit that you get a power supply that has sufficient output for the Pi's use.

If you don't have a power supply that has enough power, you'll get weird things happening.

It'll work sometimes and not others.

It will just work for awhile and then suddenly not work.

Just kind of bizarre things like that. So if you do have problems like that and you don't have a power supply that came with a kit, make sure that the output of the power supply is sufficient for the Raspberry Pi.

Let's start putting this together.

Everything's plugged in now, including the power supply into the wall.

I've got the software running on the computer to capture the screen.

I'm using OBS by the way just to record everything.

It's Open Broadcast Software I believe is what it's called and we're just using that as screen capture at this point off the HDMI input and the little converter thingy that I have.

Let's turn it on and see what happens.

First time startup

Down here in the corner I have overlaid a time code on the screen capture.

I'll be speeding up through parts of this so we don't have to wait during the entire video.

The time code will show the actual length of time it took in real life.

It takes a bit to start up and now we have a background with this welcome message.

I'm going to go ahead and hit Next and now we get a chance to setup our country, language and time zone.

I'll set mine for the United States and since I'm in Mountain Time, I'll select Boise.

Clicking Next it takes a couple seconds to set that and now we have the opportunity to set the password for the main account.

I'll put that in here what I want to use and click Next again.

Now it's asking about screen setup.

We can see around the outside edges here that we have a black border where the background screen doesn't take up the whole screen.

This has to do with different HDMI display devices and sometimes you'll see these bars and sometimes you won't.

Since we see them here, I'm going to click this check box and that should remove them in the future.

So now I'll click Next to save this.

And the next step is it's looking for wireless networks.

We can see a bunch from the neighborhood here so I'll scroll down here and select mine and it refreshes the list and now I have to select it again and hit Next.

And now it's asking for my wireless network password. I'll put that in and continue on.

And now it wants to update the software. I'm going to click Next and...

uh, oh. For some reason it didn't connect to the network. I'll have to look into that.

For now, we'll just move along. That's something that I can do in the future.

And I guess that's it for the setup wizard. It's going to reboot and let's see what happens.

OK. That didn't take too long.

Now we can see the whole screen is being used. We don't have the black borders, so that worked.

In the top right corner here we can see that we now have a network connection.

Now let's go look at the software installer.

I'll go over here to the menu and click on the Raspberry Pi icon to pull the menu down and then I'll go down here into Preferences.

Let's start with this Recommended software option.

It'll start off by checking for updates so it's going out to the network and seeing what's different between what's been released now and what the software was originally setup for.

Well that took about a minute. Now we can see all the menu items that are part of the recommended list for the Raspberry Pi ecosystem.

On the left we have different categories and when you select one it shows the items in that list.

You can check or uncheck the box on the far right to add or remove the options that you want installed on your particular Raspberry Pi.

After you have everything you want selected, click Apply and it'll start installing or removing as you've directed.

This may take a bit depending on what you've selected and the speed of your internet connection.

Fortunately it does a good job of telling you what it's doing with all the status messages and the progress bar.

After it's gone through and figured everything out, we get this completion dialog when it finishes.

If I hit Apply again, we'll see that nothing happens since it's all caught up.

So I hit Close to finish this step.

And so now if we look here in the menus, we can see that it installed the software that we asked for.

Now I want to make sure that the operating system is up to date.

To do that, I'm going to go to the terminal window and run a command.

"sudo apt update" will check for updates for everything that's installed on the Pi, both at the base operating system level as well as any additionally installed applications.

It takes a little bit, but generally not terribly long.

When it finishes, we get back to the command prompt.

All this has really done is update some internal lists so that it knows what needs to be updated. It hasn't actually done any updates.

To do the actual updates, I'm going to run the command "sudo apt full-upgrade".

This will compare what I have installed to the update list and tell me what needs to be changed.

I have the option to continue or not. Hitting return selects the default Yes answer that's indicated by the capital Y and off it goes.

This does take awhile. It's a two step process. First it has to download all the actual items that it needs to install and then it has to actually install them.

Again, it does provide good feedback while it's doing this but it may take some time depending on how much needs to be changed and the speed of your internet.

In this situation, it took between 7 and 8 minutes that I've sped up through here.

Now that the updating is all done, I want to see how much storage space I have available for future development.

I'm going to use the "df" command with the "-h" option.

On the first line it's showing that I have 3.1 gig used and 110 gig is available.

That's out of 128 gig SD card. So that'd not doing too bad.

There is some overhead for the operating system of course and things like that.

The update process downloaded a bunch of files that really aren't needed anymore.

To clean those up I'm going to use a "sudo apt clean" command. That doesn't take any time to run. It just returns immediately.

Running the "df -h" command again shows that now I have 3.0 gig used, freeing up about 100 megabytes. Not a whole lot, but every little bit counts.

Now I'm done setting this up and so we're going to use the exit command to close the terminal.

All told, that took around 19 minutes to do the initial setup and now the Raspberry Pi is ready to be used.

For now I'm going to shut it down by selecting Logout and then clicking Shutdown.

You always want to make sure you do this when you shutdown so that everything gets written out to the SD card properly.

Do you have a Raspberry Pi now? Or are you thinking about getting one? What are your plans for it? Leave a comment down below. I'd love to hear about it.

I'll see you over here in this video that YouTube thinks you're going to enjoy.

And when making things remember...
Perfection's not required.
Fun is!

Friday, October 25, 2019

What's Inside A Hard Disk | Equipment Autopsy


Description

Ever wonder what's inside a hard disk drive? In this equipment autopsy, Harley takes apart an old hard drive to see what's inside and explain how they work.

There are other computer related videos in this 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 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 What's Inside A Hard Disk | Equipment Autopsy

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

Transcript

Coming soon

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!

Monday, February 13, 2017

How to Make a Digital Valentine's Day Card


Description

Valentine's Day is tomorrow. Here's how to make a digital card to capture the heart of your sweetie. Well, OK, that might be overstating things a bit, but Harley does show an algorithmic way using trigonometry to generate a beating heart animation in an easy to use programming environment called Processing. This was inspired by a video LeiosOS posted last week.

The original inspiration: LeiosOS: Drawing a heart
Wolfram algorithm site: Heart shaped graphs

For a written transcript, go to How to Make A Digital Valentine's Day Card

Music and special effects under Creative Commons License By Attribution 3.0
Intro/Exit: "Hot Swing" by Kevin MacLeod at http://incompetech.com
Incidental: “Carefree” by Kevin MacLeod at http://incompetech.com

livingroom_light_switch by AlienXXX at http://freesound.com

Transcript

Today at the House of Hacks we're going to make a high-tech Valentine's Day greeting.

[Music]

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

I recently ran across a new-to-me programming channel who's name I won't even begin to try to pronounce but I will link to in the cards and description below.

He did a video about drawing a heart where he used a bit of C code and his own graphics library.

I want to take his idea, expand a bit on why it works and show how to use the Processing programming environment to do the same thing.

First let's look at generating shapes...

Many people get overwhelmed by the thought of trigonometry with its sine and cosine, angles and other related things, but at its core, it’s really pretty simple.

Remember the old cartesian graph from math class?

It had an x-axis and a y-axis and points could be located on this graph using just two coordinates.

On this graph, let’s draw a circle with its center at the origin with a radius of one.

Now, let’s imagine a line starting at the origin and going through the circle.

We can draw this line at any angle from the x axis.

If it is on the axis it will be 0 degrees.

Regardless of where we draw it, it’s going to intersect the circle at only one place.

That one place will have an x and y coordinate that, by definition, is the value of the cosine and sine functions at that angle.

So, for 0 degrees, the place where the circle intersects the x-axis, cosine will be 1 and sine will be 0.

As the angle increases, the x value decreases and the y value increases until we get to 90 degrees.

This lies on the y axis where cosine is 0 and sine is 1.

As the angle continues to increase, the x and y values continue to change, always between 0 and 1, always on the circle.

And that’s the fundamental theory behind trigonometry, everything else is derived from this.

Now let’s plot these points a bit differently.

On the x axis, let’s plot the angle and on the y axis, let’s plot of value of sine remembering that sine is the y value on our original circle.

At 0 degrees, sine is 0 so we start at the origin.

As the angle increases, sine increases until we get to 90 degrees and reach 1, then it starts decreasing as we move into the second quadrant of the circle.

At 180 degrees sine is back to 0.

As the angle continues to increase, the y coordinate of our circle drops into the negative values in the third quadrant until it reaches -1 at 270 degrees.

Finally in the fourth quadrant, we see y coming back up to 0.

After this, the cycle simple repeats itself as higher angles are duplicates of the previous angles.

Now, doing the same thing with cosine, at 0 degrees, cosine is 1 since it represents the x value on the circle.

As the angle increases, x decreases to 0 at 90 degrees, -1 at 180, back up to 0 at 270 and finally 1 at 360 degrees, the place we started.

These functions are great for describing a lot of things that are periodic in nature, things that fluctuate between two values.

If we multiply the results of sine or cosine we can make these graphs fluctuate by a different amount.

For example, here’s the result of multiplying the sine by 2.

And if we multiply the angle by a value, the frequency of the fluctuation will increase or decrease.

Here’s what it looks like if we multiply the angle by two.

Things can get really wild if we start adding these two curves together.

Or subtracting them.

Or multiplying them.

Or doing anything else really.

Sines and Cosines are the basis for a lot of things in our modern world.

Today we’re going to see how they can be used to send a message to our sweetheart.

Processing is a programming environment that was developed about 15 years ago and designed to teach the basics of programming within a visual context.

Since it was designed with a visual context in mind, it’s great for experimenting with graphics and drawing things.

The Processing.org website has free installers for Windows, Linux and Macs.

Just download the installer and run it.

This gives us a a Processing environment that, once started, we can start writing programs in.

Let's look at a simple program to draw a circle.

We first define the size of our canvas, the color of our background and the color we want to draw in.

Then we’re going to define a variable to scale our circle by and an offset for the x and y coordinates.

These are needed because sine and cosine return values around the cartesian origin but the coordinate system of the Processing screen is based with 0,0 in the upper left corner of the canvas.

Then we’re going to define a loop from 0 to twice PI, going in small increments.

We used twice PI here because in computers cosine and sine typically use what are called radians instead of degrees as their inputs.

This is just fine though because there’s a one to one mapping between degrees and radians where PI is 180 degrees and two PI is 360 degrees.

Inside the loop we set x to the cosine value of the loop variable and y to the sine value of the loop variable.

Then we’re simply going to plot that point, offset and scaled by the previously defined values.

Let's save our work at this point.

When we press the arrow button in the top tool bar, our program runs and we get this nice circle.

Now that we have the basics of creating a circle, how’s this help us with our Valentine Day project?

A web search for “heart drawing formula” leads us to the Wolfram site that has a number of different formulas for drawing a heart shape.

The sixth one in particular lends itself well to the program we have for drawing a circle.

All we have to do is change the assignments to x and y to get something that looks like a heart.

One of the cool things about the Processing environment is it works well for animating things.

If we put the statements before the loop in a function called setup they will get called one time when we run our program.

Then if we put the loop inside a method called draw, it will get continually called over and over again.

But because we’re drawing the same thing over and over, it's not going to be too exciting.

So before running this, let's add a line to change the scaling each time the draw method is called and adjust a control parameter to keep the scale between a couple values.

Finally, move the background call from setup into draw so it happens every time draw is called. This will clear our canvas each time.

Now let’s run this.

Ah, a nice beating heart.

This is cool and all, but it’s hard to show our special someone.

By adding a line to the end of our draw method, we can tell Processing to save our drawing to a file.

Now let's run this for a little bit, stop it and go look at where we saved our program.

We can see a bunch of individual snapshots of each frame of our animation.

In one last step, we can go to Processing’s Tools menu and select Movie Maker.

It gives us a dialog where we can select the directory containing the shots of our animations and press the Create Movie button.

This compiles our individual images into a MOV file that we can e-mail to our intended.

[Music]

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

I believe everyone has a God-given creative spark.

Sometimes this manifests through making things with a mechanical and technical bent.

Through this channel I hope to inspire, educate and encourage these types of makers in their creative endeavors.

Usually this involves various physical media like wood, metal, electronics, photography but sometimes other things, like programming.

If this sounds interesting to you, go ahead and subscribe and I’ll see you again in the next video.

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

Thursday, August 18, 2016

How to install a free virtual machine for the first time


Description

Simply stated, Virtual machines (VMs) are computers inside computers. They are one of the best kept secrets in computers, particularly for consumers. Even people who have been involved with computer technology for a while can be intimidated by them but they are not that hard to use. In fact most web apps are harder to use than setting up a VM.

In this episode of the House of Hacks, Harley removes the shroud of mystery surrounding them and shows how easy they are to work with. In this video, he covers:
1) What is a virtual machine?
2) Why use a virtual machine?
3) How does a virtual machine work?
4) What choices are there for virtual machines?
5) What kind of system is needed to run virtual machines?
6) How to install VIrtualBox software.
7) How to create a virtual machine.
8) How to install Windows on a VM.
9) How to install Linux on a VM.
10) Take a one question survey.

References

Application virtualization, past and future
Wikipedia: Virtual Machine
History of Virtualization
Wikipedia: Comparison of platform virtualization software

Music under Creative Commons License By Attribution 3.0.
Intro/Exit: "Hot Swing" by Kevin MacLeod at http://incompetech.com
Sound effect: living-room-light-switch by alienxxx at http://freesound.org

Transcript

Want to run software for an operating system that’s not installed on your computer?

Want to have different computer configurations for different purposes?

Do you want to try out some software without the risk of installing it on your computer?

Virtual Machines are the answer to all these questions.

Virtual Machine software is really cool technology that can solve a variety of different problems but it can be a bit mysterious and intimidating if you haven’t used it before. Today at the House of Hacks, my aim is to remove that shroud of mystery and show how easy they are to use.

[Intro]

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

While virtual machine technology has been around since the 60s, in the late 90s a company called VMWare released software for PCs that pushed it onto mainstream commodity hardware.

Since then, that software has matured with many more features and additional companies have come into the market to give more choices.

Today I’m going to give a brief overview of
what is a virtual machine,
why use a virtual machine,
how does a virtual machine work,
what choices are there for virtual machine software,
what kind of system do you need to run virtual machines,
how to install VIrtualBox software,
how to create a virtual machine,
how to setup two simple VMs for Windows and Linux
and finally there’s a one question survey at the end.

That’s a lot to cover and if you want to skip to the next section, click up here or in the description below.

A virtual machine is a software package that creates another computer, a virtual computer, inside your real computer. There are a couple ways of doing this.

One way is to emulate the hardware.

Examples are Apple ][ emulators that allow you to run Apple ][ software on a PC. Another example is phone emulators that allow you to develop mobile applications on a PC.

In these cases, the virtual computer hardware is likely a completely different CPU architecture from your host computer.

This is not what I'm talking about today.

Another type of software falling into this category is software written to support a programming language.

In this case an abstract computer is defined and the software implements this particular computer.

Examples of this are the JVM for Java, the Perl virtual machine for Perl or the .NET runtime engine for .NET languages.

Again, this type of virtualization is not the topic for today.

For the purposes of this video, virtual machine software is software that partitions part of the real hardware and provides those resources to the software that's installed inside of it.

This virtual computer, or guest, is basically just like your real, or host, computer hardware.

The guest computer has its own memory, disks, video adapters and network ports that are inside, but separate from the host.

To the host computer it looks like any other application. To software inside the virtual computer, it looks just like any other real computer running any operating system you want.

Virtual machines are great whenever you want to isolate software from your computer or from other software.

One example might be on your home computer with kids. Create a virtual machine for their exclusive use and any changes they make will be isolated to their machine.

If they mess something up too bad, just restore their machine to a snapshot and it's back to a known state.

Another example might be you have a machine with one operating system on it and you want to run software designed for a different operating system.

Simply create a VM and install the other operating system in it to run that other software.

For example, I have a Mac with a Windows VM on it to run Windows Adobe products.

A final example might be in software development where you have one VM for back-end server development and a different VM for front-end client development.

Another use is to test software where you have multiple VMs setup with different operating systems and base dependencies for a product. You then save a snapshot of those setups and return to them at the start of each testing cycle.

You can even simulate a network of different computers all running inside a single host computer.

Virtual machine software provides an environment into which you can install an operating system.

The actual computer you install this software on is called the host. The virtual machines you create inside this software are called guests.

When you create a guest machine, you specify various aspects of its configuration.

The main ones are how much memory it should have, how many CPU cores to use, how large the disk is and networking options.

You want to set these to be less than what your real, host computer has. If they are set too high, the guest machine may take up too many resources from the host and slow things down.

Once you've created the guest machine you essentially have an empty computer ready to install an operating system into.

The guest does not have to have the same operating system as the host.

You can have different operating systems running on the same computer at the same time. This is really cool!

When you create a guest machine, its hard drive is stored inside a file on your host computer.

So you can move guests from one host computer to another or back it up by simply copying that one file.

It's also possible to setup a directory on your host computer as a shared file on the guest. This shows up as a drive in the guest and allows you to share files between the host and a guest.

If the same directory is shared between the host and multiple guests, then the guests effectively can see each others files.

However, the files that are stored on the guest's hard drive are only visible to that guest. Neither the host nor other guests can see those files.

There are many, many choices for VM software. There's a link in the description to a Wiki page with a huge number of them. In the PC world, there are three big names: VMWare, VirtualBox and Hyper-V.

VMWare was an early entrant in this space with a history going back to 1998. It has a huge number of different options and configurations.

They have many different software configurations to run virtual machines on anything from a single computer to managing a huge farm of machines in a data center environment.

Hyper-V is a product now owned by Microsoft and is at the core of their server management. Like VMWare, it allows running virtual machines on anything from a single PC to a data center.

VirtualBox started as an proprietary licensed product and eventually went open source. It was first acquired by Sun and subsequently Oracle when they bought Sun.

Its focus is on just the desktop and will run on Windows, Linux or Mac OS X operating systems.

VMWare and Hyper-V are large, flexible but complicated products. Their main focus is more on virtual server management in large data centers.

While they have products that run locally on a single computer, because of their focus on servers, in my experience they are more complicated to install and use.

Also, they are more limited in what operating systems they will run on.

I find VirtualBox to work perfect for my single user, non-server needs for both work and personal use. This is the software I will be demonstrating today.

The real, host computer needs to be reasonably powerful with an Intel or AMD processor. Most modern PCs fall into this category.

The two most important requirements for the host are memory and disk space.

At a minimum, you need to take the minimum memory requirements for the host operating system and add the minimum memory requirements of the guest operating system you want to run.

Of course with all things memory related, the more the better.

The disk needs to be able to store both the host operating system and any related software as well as any guest operating systems and their related software.

The VirtualBox software itself doesn’t need too much disk space, only a couple 10s of megabytes. However operating systems these days typically run into the 10s of gigabytes.

So plan on 10-50 gigabytes per guest machine in addition to the host’s needs.

To create a virtual machine, you first need to install the virtual machine software, VirtualBox in this example, on the host computer. Download VirtualBox from virtualbox.org for your operating system.

This installs just like any other software package: on Windows they have an exe file, on OS X they have a dmg file and on Linux they have different package formats for different distributions.

After downloading, start the installer appropriate for your machine. In this example, I’m on a MacBook Pro so I have a dmg file that’s mounted as a disk.

Double clicking the disk opens the installer. Double clicking again opens the pkg file and I can proceed through the typical installation process.

On a Windows machine, you will probably get a couple more prompts as it installs some low level drivers and disables network communications momentarily.

On a Linux machine, you’d use the package manager for your distribution to install the download.

Once installed, you click on the VirtualBox icon to start the VirtualBox manager. This is where you manage your virtual machines.

On the left is a list of all the guest machines you’ve created. Of course this starts out empty.

On the right is a panel that shows details about the selected VM. If you have multiple, related VMs, you can group them together to expand or collapse the group.

Across the top is a toolbar with common actions.

To create a new virtual machine, click the New button on the top of the toolbar. This wizard pops up.

First put in the name of the virtual machine. This name is what shows up the manager on the left side of the VM manager.

Then select the type and version of the operating system that will be installed. In this case, I’m selecting Windows. When ready, click Continue.

Next you need to select the amount of memory that should be used by the VM. The slider bar is colored to recommend values based on what the host system has.

You cannot allocate more than is installed on the host computer, so this maximum value will vary depending on your particular computer.

The host computer needs some memory for basic operations, so it’s recommended you stay in this green zone.

I tend to use no more than 50% of the maximum number. If you plan on running multiple VMs at the same time, you don’t want the combined memory usage of all the VMs to exceed the green part of this slider. Once the memory size is selected, click Continue.

Now the hard drive for the virtual machine needs to be configured. A disk in the guest computer is simply a file on the host, so the following wizard pages control this file.

The first page allows you to select the source of the file. The first option is if there shouldn’t be a disk. The second is to create a new disk. The third is to use an existing disk.

Generally I always want to use the default and create a new disk. The other options are for special situations and I rarely use them. Click Continue when ready.

On the next page the file format for the virtual hard drive is specified. The different options are for compatibility with other virtual machine software packages.

I always use the VDI format since I always use VirutalBox and don’t care about cross-compatibility. Click Continue to move to the next step.

This step allows you to select whether the hard drive should be dynamically or statically allocated. Dynamic allocation means it starts out small and grows only as needed. This option minimizes space on the host computer.

Fixed size means the hard drive is set to its maximum size when it’s created and does not grow any larger. This option may take a little longer to create but may operate faster. It will take a fixed amount of space on the host, so once it’s allocated, it won’t take up any more space.

Which option you use depends on how many virtual machines you will create and how much free disk space you have on the host computer.

I tend to have quite a few virtual machines so I select the default dynamic mode. This helps minimize disk usage on the host. When ready, click Continue.

The final step allows you to specify the name of the hard drive file name and its maximum size. The name defaults to be the same as was used in step 1 for the virtual machine itself.

The size value entered here is what is reported to the guest operating system as its disk size.

Remember those two options we just had in the previous step? This will be the maximum size of dynamic disk files or the size of the fixed disk file.

The size needs to be large enough to contain the operating system and any programs and data that will be put in it. But you don’t want it to be so large it takes all the disk away from the host computer.

Typically I set this to be in the 30 to 40 GB size range. When this is set to what you want, click Create.

The wizard will close and a new virtual machine shows up in the left side of the manager window. You now have a new, empty virtual machine.

With the machine selected in the manager, click the Settings button and you get a dialog that allows you to change many parameters of the machine and how it appears to the guest operating system. This has all the items from the wizard we just went through plus many other options.

Generally these don’t need to be changed from their defaults with one exception: the CD drive in the storage tab. This is used to install an operating system so the virtual machine is actually capable of doing something.

The virtual machine can use the physical CD drive in the host computer as its CD or any ISO file can be mounted without having to have a physical CD. I generally download ISO files and use them.

And now we get to install Windows. In this example, I select a Windows 10 installation ISO to put Windows 10 on my virtual machine.

I have licenses to all versions of Windows installation images via a Microsoft subscription service and can download these ISO files.

If you don’t have access to this, you can purchase a Windows installation disk and place it in the host computer’s drive. Then select the option to use the host’s CD drive.

Now that the VM is created and an installation disk attached to the CD drive, start the virtual machine by pressing the Start button in the toolbar.

A new window opens up containing the virtual machine. First you see a VirtualBox boot screen and then we see the Windows installation screen.

At this point we’re just walking through a standard Windows install procedure.

Select the values you want on each screen.

When it gets to the custom install/upgrade screen. There isn’t any information on the HD to be able to do an upgrade. If you select upgrade you’ll have to restart the installation process so be sure to choose the custom install.

The custom install allows you to partition the disk. In this case, the disk is actually the VM’s hard drive stored in the file indicated in the VM configuration. I just use the entire disk.

Depending on the installer, you may get a warning saying you are about to overwrite all the data on the disk.

This warning is always a bit disconcerting, but remember, we’re inside a virtual machine, so the only data we could lose is the data inside the blank file we just created.

And now we just wait for the installation process to finish.

When it’s all done, we now have Windows 10 running on our virtual machine and almost ready for use.

Let's shut it down just like any other computer.

Then remove the CD from the virtual machine by going back into settings and selecting the option to remove the mounted CD.

The guest operating system is installed and ready for use, but there’s one more step to help make it easier to use. Virtual Box has some drivers that can be installed that make the virtual machine nicer to use.

To install these, select the Devices menu for the Virtual Box application. On this menu, select the “Insert Guest Additions CD image…” option.

If the VM isn’t running, start it and then pull up Windows Explorer. Select the CD drive and then start the installer. Select all the default options and let it do its thing.

This software does many things to make the VM easier to use.

For example, it allows the clipboard to be shared between the host and guest operating systems,
it increases the options for different network configurations
and allows the guest operating system to resize to whatever size the window is set to rather than the fixed sizes based on common hardware configurations.

And that’s all there is to setting up a Windows virtual machine.

Next we move onto installing Linux.

We start with a freshly created virtual machine as described earlier. I select a Linux installation ISO I downloaded. All distributions I’ve seen have an ISO option to use for installation. This one is from Ubuntu.

Once the ISO is selected for the CD drive we’re ready to start the virtual machine from the toolbar.

A new window is shown with a VirtualBox boot screen. Shortly after that we see the start of the Linux install process.

Just go through the prompts as if installing on a real machine. The default values were appropriate for my situation but you can change them to something different if you need.

Similar to the Windows install, we get this warning indicating we’re going to overwrite the whole drive. This is OK since the whole drive in the context of a virtual machine is contained in the file created to contain the VMs hard drive. It’s not the physical hard drive of our computer.

Enter the user name you want to use and your password to login into the virtual machine. Or you can have it login automatically if you’d prefer.

Once all the setup information is given, it’s just a matter of waiting for the installation to finish.

When it’s all done, we now have Linux running on our virtual machine, almost ready for use.

Just like Windows, the first thing to do to improve usability is to install the guest additions. On the VirtualBox Device menu, select the “Insert Guest Additions CD image” option.

Ubuntu will detect the new disk and ask if you want to run the installer.

Other distributions may require you to mount the CD and/or run the installer manually.

In this case, I’m going to run it and enter the password to authorize the installation.

As mentioned before, this software does makes the VM easier to use.

For example, it allows the clipboard to be shared between the host and guest operating systems,
it increases the options for different network configurations
and allows the guest operating system to resize to whatever size the window is set to rather than the fixed sizes based on common hardware configurations.

When the Guest Additions are done, I reboot the system. In theory this isn’t really needed, but I do it out of habit.

Now the Linux virtual machine is ready for use.

And that's all there is to setting up virtual machines. Basically it's pretty easy.

I’d appreciate some feedback in this short, one question survey. Would you be interested in videos showing advanced features of virtual machines and how they can be used? Select an answer in the survey section above.

In conclusion, join me in the comments below; I’d be interested to know if you’ve used a VM before or not and, if you have, what you have used if for, or plan to use it for in the future.

If this is your first time here at House of Hacks: Welcome, I’m glad you’re here and would love to have you subscribe. I believe everyone has a God-given creative spark. Sometimes this manifests through making things with a mechanical or technical bent.

Through this channel I hope to inspire, educate and encourage these types of makers in their creative endeavors. Usually this involves various physical media like wood, metal, electronics, photography and other similar materials. If this sounds interesting to you, go ahead and subscribe and I’ll see you again in the next video.

Now, go make something. It doesn’t have to be perfect, just have fun!

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!