The picture above shows what is known (for historical reasons) as a circuit. It depicts the story of what happens to the qubits during the program, from left to right. In this particular example, not much is happening. We set up eight qubits and number them from 0 to 7 (because that’s how programmers like to do things).

After setting up the 8 qubits, we immediately measure them. This is simply the process of seeing which bit value they represent. Qubits are always initialized to give the answer 0 if you immediately measure them. So if we press ‘simulate’, we should get the bit string 00000000 : a 0 from each qubit.

Programs made on the composer give us a histogram. This is because sometimes quantum computers have some randomness in their results. But since we aren’t doing anything quantum, we get one result with certainty: exactly the 00000000 that we expected.

To encode a different string, we need what is known as a NOT gate. This is the most basic operation that you can do in a computer. It simply flips the bit value: 0 becomes 1 and 1 becomes 0 . On the composer, we do this by dragging over the green box marked X. Let’s do it on qubit 7.

Now our computer outputs the string 10000000 instead.

The bit we flipped, which comes from qubit 7, lives on the far left of the string. This is because the composer numbers the bits in a string from left to right. If this convention seems odd to you, don’t worry. It seems odd to lots of other people too, and some prefer to number their bits the other way around. But this system certainly has its advantages when we are using the bits to represent numbers. This is because means that qubit 7 is telling us about how many 2⁷s we have in our number. So by flipping this bit, we’ve now written the number 128 in our simple 8-bit computer.

Now try out writing another number for yourself. You could do your age, for example. Just use Google to find out what the number looks like in binary (if it includes a ‘0b’, just ignore it), and then add some 0 s to the left side if you are younger than 64.

Now we know how to encode information in a computer. The next step is to process it. To take an input that we have encoded, and turn it into an output that we need.

Back to school

For that we need a problem to solve. Let’s do some basic maths. In primary school you will have learned how to take large mathematical problems and break them down into manageable pieces. For example, how would you go about solving the following?

9213

+ 1854 = ????

One way is to do it digit by digit, from right to left. So we start with 3+4

9213

+ 1854 = ???7

And then 1+5

9213

+ 1854 = ??67

Then we have 2+8=10. Since this is a two digit answer, we need to carry the one over to the next column.

9213

+ 1854

¹

= ?067

Finally we have 9+1+1, and get our answer

9213

+ 1854

¹

= 11067

This may just be simple addition, but it demonstrates the principles behind all algorithms. Whether the algorithm is designed to solve mathematical problems or process text or images, we always try to make things easy with small and simple steps.

To see what the smallest and simplest steps look like, let’s do the above addition problem again, but in binary.

10001111111101

+ 00011100111110 = ??????????????

Note that the second number has a bunch of extra 0s on the left. This just serves to make the two strings the same length.

Our first task is to do the 1+0 for the column on the right. In binary, as in any number system, the answer is 1 . We get the same result for the 0+1 of the second column.

10001111111101

+ 00011100111110 = ????????????11

Next we have 1+1 . As you’ll surely be aware, 1+1=2. In binary, the number 2 is written 10 , and so requires two bits. This means that we need to carry the 1 .

10001111111101

+ 00011100111110

¹

= ???????????011

The next column now requires us to calculate 1+1+1. This means adding three numbers together, so things are getting complicated for our computer. But we can just break things down into smaller chunks again. To do it in a way that only ever requires us to add two bits together, we can start with just the first two 1 s.

1

+ 1

= 10

Then we add the final 1 to the result using our usual method of going through the columns.

10

+ 01

= 11

The final answer is 11 (also known as 3).

Now we can get back to the bigger problem. With the answer of 11 , we have another carry bit.

10001111111101

+ 00011100111110

¹¹

= ??????????1011

So now we have another 1+1+1 to do. But we already know how to do that, so it’s not a big deal.

In fact, everything left so far is something we already know how to do. This is because, if you break everything down into adding just two bits, there’s only four possible things you’ll ever need to calculate. Here are the four basic sums (we’ll write all the answers with two bits to be consistent).

0+0 = 00

0+1 = 01

1+0 = 01

1+1 = 10

If our computer can do these, it can add anything. This is called a half adder. Let’s make one with the composer.

Making a half adder

Since we are using the composer, our half adder will look a little something like this.