Lesson 1 - Binary Numbers
What is binary?
At their most simple level, computers are basically a collection of circuits turned on or off. We use binary to represent these circuits.
Binary is a counting system. Counting systems are the symbols used to represent numbers. The most widely used counting system is known as decimal. This is the number system that you are familiar with and use in your every day life. In decimal, there are ten symbols 0 1 2 3 4 5 6 7 8 9 used to represent different numbers (zero through nine). When we run out of symbols to represent our numbers, we add a new place value. For example, 9 is the highest symbol in the decimal number system, when we represent the number ten, we add a place value and start the one’s place at 0.
9 -> 10
Binary is a counting system that only uses two symbols to represent a number (1 and 0). We use it for computer science because it allows us to represent a semi-conductor that is turned off with a 0. We represent a semi-conductor that is turned on with a 1. You can also think of binary numbers in terms of True (1) and False (0). We call each place value that contains a 1 or a 0 a bit. 8 bits make up one byte. Modern computers are built on millions of bytes that are connected.
How to Convert between Binary and Decimal
Binary and decimal essentially mean the same thing. They are both counting systems used to represent numerical values. Whether we write the number seven as 111 (in binary) or 7 (in decimal) does not make a difference to humans. They both represent a value of seven. Computers use binary because it allows for mathematical operations to be implemented as circuits. Doing this with a decimal counting system would be impossible. In order to make binary operations more readable to humans, it is often useful to convert from binary to decimal.
Convert from Binary to Decimal.
- Index the binary number
Before we convert our number, we must take a look at the indices or digit places of the binary number. We list the indices as above, with the right-most index starting at zero. Then we increase the index by one with every step to the left. Just like in decimal, as we move further to the left in our number, our digits increase in significance meaning that digits further to the left represent larger numbers. - We convert binary to decimal summing
d*2^iover all indices.irepresents the index anddrepresents the value stored at the index. So we convert the number above like this:

Convert from Decimal to Binary
To convert a decimal number to binary, we do the inverse of the operation above. The steps are detailed below
-
Find the largest index. We can use logarithms for this. The largest index for any number
nis equal tofloor(log2(n))
The symbols that look like L’s enclosing the log operator are known as theflooroperator. They simply indicate to round down to the nearest whole number. For examplefloor(4.5) = 4. To convert the decimal number12to binary first we find the largest index (L).
The value ofnat this index will be1. -
Convert the remaining digits to binary. We know
2^3 = 8and we are trying to convert the number12to binary. In the last step, we concluded that the value at index=3 is 1. The decimal value of the number1000is8. So we subtract1*2^3fromn. This result gives us:12-8 = 4. -
Represent the remaining value in binary. We must repeat steps 1-2 until our remainder is zero. So we now convert the number
4to binary. The largest index of4is2. So now we do4 - 1*2^(2) = 0. Since this equals zero, we know we are done. So the value of12in binary is1100. If our remainder was greater than zero, we would repeat steps 1 and 2 on the next indices. If the largest index of our remainder less than the next2^iwhereiis our next index, we enter a0at indexiand proceed to the next index.
Practice
1. Write the following decimal numbers as 4-bit binary numbers.
0
1
2
3
4
5
7
14
8
Solutions
| Decimal | Binary |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 7 | 0111 |
| 14 | 1110 |
| 8 | 1000 |
2. Write the following 4-bit binary numbers in decimal.
0101
1010
1111
0010
1000
1101
Solutions
| Binary | Decimal |
|---|---|
| 0101 | 5 |
| 1010 | 10 |
| 1111 | 15 |
| 0010 | 2 |
| 1000 | 8 |
| 1101 | 13 |
Activity 1: Numbers as Redstone
Using what you know about binary, pick a random positive number and write it by turning Redstone torches (or Redstone Lamps) on or off. Redstone torches that are turned on represent a 1 and Redstone torches that are turned off represent a 0.

