Binary

What is Binary

In the world of computers, everything is about using switches to represent information. These switches are like tiny buttons that can be in one of two positions: on or off. We call these positions '1' and '0'. Now, you might wonder why computers use this binary system instead of our familiar decimal system with numbers from 0 to 9.

Well, it turns out that using just two states, '1' and '0', makes things really simple for computers. It is like speaking a language that computers easily understand. These 1s and 0s are called 'binary digits' or 'bits'. When we group these bits together, like a string of beads, they can represent more complex information.

In the real world, computers have billions of these bits working together to handle tasks. Using binary makes it easier to build reliable and efficient systems because it's straightforward for electronic components to process and store binary data. So, even though binary might seem a bit strange to us, it is the perfect way for computers to talk and think.

How Does Binary Work

Above, we saw what binary is, but how does it work? Imagine you have a bunch of light switches, and each switch can be either off (0) or on (1). When we count in binary, we start with 0, just like in decimal. But after that, things change quickly. When we get to 1, we run out of single digits, so we add another digit to the left and start over at 0, making 10 (the equivalent of 2 in decimal).

This might sound confusing at first, but it's actually quite clever. Computers use these binary digits, or 'bits,' to represent all sorts of information. By arranging bits in different patterns, we can store numbers, letters, colors, and even complex instructions that computers understand.

The reason computers use binary is because their internal components, like transistors, can easily switch between two states, much like our light switches. This simplicity allows computers to perform calculations and process data at incredible speeds. So, while binary might seem unusual to us, it is the foundation of how computers think and work.

Bits, Bytes, Nibbles, and Crumbs

Bits and bytes are important to understand when dealing with computers. These are terms you probably hear a lot and have already been mentioned above. But let us take a look at each of these individually to help make sense of these terms. In addition to bits and bytes, we will also examine nibbles and crumbs.

Bits: We know that computers use binary as a simple way to talk to each other, using just two symbols: 0 and 1. Think of each of these symbols as a "bit." A bit is like a tiny switch that can be turned off (0) or on (1), and it is the smallest thing a computer understands.

Bytes: Now, when we group bits together, we get something more useful. A bunch of 8 bits is called a "byte." It is like a small package of data that can show a letter, number, or even a special character. When you press a key on your keyboard, like the letter "A," the computer uses a byte to know what letter you want to see.

Nibbles: Sometimes, we do not need a whole byte – just a smaller piece. That is where a "nibble" comes in. It is like a mini-package of 4 bits. In the past, people used nibbles to talk about simple things like numbers and basic information. You will see more about nibbles when you begin working with hexadecimal (base-16).

Crumbs (Non-standard term): "Crumb" is not a regular word within computer science. It may be used as a fun comparison and generally refers to two bits. But normally, in computer lingo, "crumb" is not a word that is commonly used or accepted. It is, however, often brought up in class, so it seemed worth mentioning in this section. 

In essence, imagine bits as the tiny building blocks of binary, bytes as handy little data packages, and nibbles as even smaller packages. Learning about these helps us understand how computers use binary to share and process information.

Counting in Binary

Before we delve into binary counting, let us first explore how we count in decimal. In our everyday counting system, which is a base 10 system, meaning we have 10 digits to work with, 0 through 9. When we reach 9 and want to count higher, we add another digit to the left, just like moving from 9 to 10. This pattern continues as we move to 99, 100, and beyond, with each new digit representing a higher place value like hundreds, thousands, and so on.

Now, in binary counting, things are simpler, yet different. Binary is a base 2 system, which means we have only 2 digits, 0 and 1. When we reach 1 in the rightmost place, we do not have any more digits remaining, so we add another digit to the left. This process continues as we move to 10 (binary), then 11, 100, 101, and so on.

As we add digits to the left in binary, their value doubles each time. For instance, 1 in the rightmost place represents 1, and if we add 1 to the left (making it 10), it's worth 2. Adding another to the left (making it 100) makes it 4, and so on.

Visualizing this progression helps. Think of each digit's value as doubling as we go left: 1, 2, 4, 8, 16, and so forth. Just like having 1s, 10s, 100s, and 1000s in decimal, in binary, having 1s, 2s, 4s, and 8s lets us count higher and higher.

Binary's simplicity helps computers perform calculations quickly and efficiently. While it might seem complex at first, visuals can make it much clearer. As you get started, try using the binary cards below to help get the feel for counting in binary. There are also practice problems below, converting decimal values to binary and binary to decimal. Click here for a different set of binary cards.

Converting Binary to Decimal

Converting a number from binary or base-2 into decimal or base-10 is like translating a message. Let us break it down into steps.

Step 1: First, write down the values of the powers of 2 above each digit, starting from 2^0 for the rightmost digit and increasing by 1 as you move to the left: 2^0(=1), 2^1(=2), 2^2(=4), 2^3(=8), and so on.

Step 2: Now, for each digit in your binary number, multiply the digit (0 or 1) by the corresponding power of 2 and write down the result.

Step 3: Now, add up all the results from Step 2.

Step 4: The final result is the decimal equivalent of your binary number.

Sample Problem With Explanation

Let us follow these steps to convert 1101 into decimal. Follow along, making your calculations on a piece of scrap paper.


Step 1: Start by writing down the values of the powers of 2 above each digit, starting from 2^0 for the rightmost digit and increasing by 1 as you move to the left: 2^0(=1), 2^1(=2), 2^2(=4), 2^3(=8). * The binary cards below can help with this step.

Step 2: Now, multiply each digit by the corresponding power of 2 and write down the results...   

      8 x 1 = 8          4 x 1 = 4          2 x 1 = 2          1 x 1 = 1


Step 3: Now, add up all the results from Step 2...   8 + 4 + 2 + 1 = 15


Step 4: The sum of the values in Step 3 gives us our final answer. So, 1101 (binary) = 15 (decimal).  

Sample Problem Without Explanation

This time, let us work through the steps of converting a binary value to a decimal value without all of the explanations, focusing on the math. Try this on a piece of scrap paper to see if you get the same answer. If not, check your work. If you cannot find your error, check with your teacher. 


Problem: Convert 11011 to decimal.

1   1  0  1  1

16s 8s 4s 2s 1s

(16 x 1) + (8 x 1) + (4 x 0) + (2 x 1) + (1 x 1) = ?

16 + 8 + 0 + 2 + 1 = 27

11011 (binary) = 27 (decimal) 

Practice

Converting Decimal to Binary

Converting a number from decimal or base-10 into binary is different than converting from binary to decimal. Let us break it down into steps.

Step 1: Divide the decimal number by '2' which gives the result along with the remainder.

Step 2: If the decimal number is even, then the result will be whole and the remainder will be '0'.

Step 3: If the decimal number is odd, then the result is not divided properly (this is called 'floor division') and it gives the remainder '1'.

Step 4: By placing all the remainders in order in such a way, the Least Significant Bit (LSB) at the top and the Most Significant Bit (MSB) at the bottom, the required binary number will be obtained.

Sample Problem With Explanation

Let us follow these steps to convert 11 into binary. Follow along, making your calculations on a piece of scrap paper.


Step 1: Start by dividing 11 by 2...   11 ÷ 2 = 5  R1  (LSB)

Step 2: Now, divide 5 by 2...   5 ÷ 2 = 2  R1

Step 3: Next, divide 2 by 2...   2 ÷ 2 = 1  R0

Step 4: After that, divide 1 by 2...   1 ÷ 2 = 0  R1  (MSB)

Step 5: Finally, arrange the remainders in order from the Most Significant Bit (MSB) to the Least Significant Bit (LSB)... giving us our final    

            answer, 1011 (binary).

Sample Problem Without Explanation

This time, let us work through the steps of converting a decimal value to a binary value without all of the explanations, focusing on the math. Try this on a piece of scrap paper to see if you get the same answer. If not, check your work. If you cannot find your error, check with your teacher. 


Problem: Convert 160 to binary.

160 ÷ 2 = 80  R0  (LSB)

80 ÷ 2 = 40  R0

40 ÷ 2 = 20  R0

20 ÷ 2 = 10  R0

10 ÷ 2 = 5  R0

5 ÷ 2 = 2  R1

2 ÷ 2 = 1  R0

1 ÷ 2 = 0  R1  (MSB)

10100000

160 (decimal) = 10100000 (binary) 

Practice

ASCII: How Binary Creates Text

Above, we examined what binary is and how computers process information using binary.  We looked at how numbers are converted from decimal to binary and from binary to decimal. Now, let us look at text – letters, numbers, punctuation marks – everything you see on a screen. Computers need a way to represent this text using their binary language. This is where ASCII comes in.

ASCII stands for "American Standard Code for Information Interchange." It is a set of rules that assigns a unique binary code to each character you can type on a keyboard. So, every letter, number, and symbol has its own specific binary pattern in ASCII.

For example, let us take the letter "A." In ASCII, the capital letter "A" is represented by the binary code 01000001. This means that if you want the computer to show an "A" on the screen, you send it the binary pattern 01000001.

When you type a letter on your keyboard, your computer's software translates that letter into its corresponding ASCII code. Let us say you type "HELLO." The computer's software looks up the ASCII codes for H, E, L, L, and O, and then converts each of these letters into their respective binary codes. These binary codes are then sent to the computer's hardware, which displays the letters on the screen using tiny pixels.

In short, binary represents text by assigning each character a unique set of ones and zeros using the ASCII code. This allows computers to understand and display the text we see on our screens.

Click to enlarge

Click to enlarge

Binary And Images

We can think of digital images as puzzles made of tiny colored dots called pixels, short for picture elements. Each pixel is a little square that can be a different color. To make these colors, we use a mix of three primary colors: red, green, and blue – this is called RGB. Computers use binary to represent colors too!

Imagine we are giving colors numbers. We give red, green, and blue numbers from 0 to 255. Why 255? It is the biggest number we can make with 8 bits (zeros and ones), which computers use a lot. Let us say we want pure red. Its RGB numbers are (255, 0, 0). Now, we turn these numbers into binary. 255 becomes 11111111, and 0 stays as 00000000.

Images are like mosaics, built from these colored pixels. Every pixel gets its own color by using these binary numbers. When we see a picture on a screen, we are actually looking at this big mosaic of tiny colored squares. This way, computers change binary code into the pictures and photos we see all around us. These pictures are called "bitmap" images because they are like a grid of colored dots that form a picture.

In short, binary helps computers create images by using binary numbers to decide what color each tiny pixel should be. It is like putting together a colorful puzzle made of ones and zeros, which eventually gives us the photos and images we enjoy on screens every day.

Binary Image Creator

In the box below, add binary code to turn pixels on or off. Write one line of code for each of the nine rows in the grid. A '1' will darken the cell while a '0' will leave it blank. A feature has been added to allow you to download your image as a .png file.