This site is retired and is no longer updated since November 2021. Please visit our new website at https://www.teamscode.org for up-to-date information!
Binary

Vocab Bar
Bit One digit in a binary number (0 or 1).
Byte A binary sequence 8 digits long.
Decimal Base ten counting - counting with ten symbols (0-9).
Binary Base two counting - counting with two symbols (0-1).

We count in base ten while computers count in base two. In base ten we have ten symbols (0-9) to represent ten possible states in each digit. However, in base two, there are only two symbols (0-1) which allows only two states in a digit. Binary is the base two method of counting which is used in computing; therefore, all code will be converted into binary before it is read by the computer.

With binary, computers are able to compute using a minimal amount of space and energy, making it the ideal system. To store the data, binary is most often stored in bytes which are numbers 8 digits long. Learning to count in binary is useful, for it helps to understand the computing process.

The table below depicts the first eight numbers in binary:

Binary to Decimal Conversion
Binary Base Ten
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7

The conversions are certainly confusing; however, binary is structured just like decimal. In base ten, we count from 0 to 9, then, once we count past 9, we start filling the next digit. In this step, the tens digit goes from 0 to 1, and the ones digit goes to 0. All counting works in this way. Counting in increments of 1, filling the current digit. When the digit is full, we empty the current digit and add to the next one. Here is an example:

    9 + 1 = 09 + 01 = 10 

Binary uses the same principle, but it is possibly easier than decimal. There are only two numbers used, 0 and 1, so instead of counting from 0 to 9 in the first digit, binary counts from 0 to 1.

Converting between different base counting types is essential for understanding binary. To count between bases, understanding the values associated with each digit is important. If we think about decimal counting, the first digit is the ‘ones digit’, the second is the ‘tens digit’, and the third is the ‘hundreds digit’. This is because numbers have different values when in different digits. Refer to the table below:

Thousands Digit Hundreds Digit Tens Digit Ones Digit
Value # x 1000 # x 100 # x 10 # x 1

In decimal, each subsequent digit is ten times as large as the previous digit. This means that a number which spans multiple digits can be broken up into a series of numbers added together. Here is an example using the number 5406:

Thousands Digit Hundreds Digit Tens Digit Ones Digit
Value 5 x 1000 4 x 100 0 x 10 6 x 1

In binary, the relationship between digits is similar to decimal except that each subsequent digit is two times as large as the previous digit rather than ten. Refer to the table below:

Eights Digit Fours Digit Twos Digit Ones Digit
Value # x 8 # x 4 # x 2 # x 1

A decimal number which represents the value of a binary number is equal to the sum of the values of each digit. This sum is calculated by adding the digit values of all digits. Here are some examples:

Binary # 00010111
Binary Digits 0 0 0 1 0 1 1 1
Digit Values 0 0 0 16 0 4 2 1
Decimal # 23


Binary # 01100110
Binary Digits 0 1 1 0 0 1 1 0
Digit Values 0 64 32 0 0 4 2 0
Decimal # 102

Converting from decimal to binary is similar to converting binary to decimal. When converting decimal to binary, instead of adding, you subtract. In this process, you subtract the largest power of the two possible, and fill the respective digit. Here is an example:

Decimal # 156
Power of Two 128 0 0 16 8 4 0 0
Binary Digits 1 0 0 1 1 1 0 0
Binary # 10011100

As seen in the example above, 128, 16, 8, and 4 are subtracted from 156 to equal zero. The numbers are then matched to their respective binary digit, and the binary number 10011100 is derived. When converting from decimal to binary, the process of converting binary to decimal is merely reversed.

Overall binary is an important process to computer programming and an important concept to understand.

Lesson Quiz

1. What is the binary equivalent of the decimal number: 145?

a. 10010001
b. 11011010
c. 00101010
d. 11111000

2. What is the decimal equivalent of the binary number: 01001010?

a. 42
b. 74
c. 88
d. 100

3. How many digits are in a byte?

a. 1
b. 4
c. 6
d. 8

Written by James Richardson

Notice any mistakes? Please email us at learn@teamscode.com so that we can fix any inaccuracies.