Do something computationally funny for money

A red nose
Image by CS4FN

It is Red nose day in the UK  the day of raising money for the comic relief charity by buying and wearing red noses and generally doing silly things for money.

Red noses are not just for red nose day though and if you ‘ve been supporting it every year, you possibly now have a lot of red noses like we do. What can you do with lots of red noses? Well one possibility is to count in red nose binary as a family or group of friends. (Order your red noses (a family pack has 4 or a school pack 25) from comic relief or make a donation to the charity there.)

Red nose binary

Let’s suppose you are a family of four. All stand in a line holding your red noses (you may want to set up a camera to film this). How many numbers can 4 red noses represent? See if you can work it out first. Then start counting:

  • No one wearing a red nose is 0,
  • the rightmost end person puts theirs on for 1,
  • they take it off and the next person puts theirs on for 2,
  • the first person puts theirs back on for 3,
  • the first two people take their noses off and the third person puts theirs on for 4
  • and so on…

The pattern we are following is the first (rightmost end) person changes their nose every time we count. The second person has the nose off for 2 then on for the next 2 counts. The third person changes theirs every fourth count (nose off for 4 then on for 4) and the last person changes theirs every eighth count (off for 8, on for 8). That gives a unique nose pattern every step of the way until eventually all the noses are off again and you have counted all the way from 0 to 15. This is exactly the pattern of binary that computers use (except they use 1s and 0s rather than wear red noses).

What is the biggest number you get to before you are back at 0? It is 15. Here is what the red nose binary pattern looks like.

The binary sequence in faces wearing red noses
Image by CS4FN

Try and count in red nose binary like this putting on and taking off red noses as fast as you can, following the pattern without making mistakes!

The numbers we have put at the top of each column are how much a red nose is worth in that column. You could write the number of the column on that person’s red nose to make this obvious. In our normal decimal way of counting, digits in each column are worth 10 times as much (1s 10s 100s, 1000s, etc) Here we are doing the same but with 2s (1s 2s 4s 8s etc). You can work out what a number represents just by adding that column number in if there is a red nose there. You ignore it if there is no red nose. So for example 13 is made up of an 8s red nose + a 4s red nose + a 1s red nose. 8 + 4 + 1 = 13.

13 in red nose binary with the 8, the 4 and the 1 red nose all worn.
Image by CS4FN

Add one more person (perhaps the dog if they are a friendly dog willing to put up with this sort of thing) with a red nose (now worth 16) to the line and how many more numbers does that now mean you can count up to? Its not just one more. You can now go through the whole original sequence twice once with the dog having no red nose, once with them having a red nose. So you can now count all the way from 0 to 31. Each time you add a new person (or pet*, though goldfish don’t tend to like it) with a red nose, you double the number you can count up to.

There is lots more you can do once you can count in red nose binary. Do red nose binary addition with three lines of friends with red noses, representing two numbers to add and compute the answer on the third line perhaps… for that you need to learn how to carry a red nose from one person to the next! Or play the game of Nim using red nose binary to work out your moves (it is the sneaky way mathematicians and computer scientists use to work out how to always win). You can even build a working computer (a Turing Machine) out of people wearing red noses…but perhaps we will save that for next year.

What else can you think of to do with red nose binary?

Paul Curzon, Queen Mary University of London

*Always make sure your pet (or other family member) has given written consent before you put a red nose on them for ethical counting.

More on computers and comedy

Magazines …

Front cover of CS4FN issue 29 – Diversity in Computing


Subscribe to be notified whenever we publish a new post to the CS4FN blog.


This blog is funded by EPSRC on research agreement EP/W033615/1.

QMUL CS4FN EPSRC logos

A Godlike Heart

A short story by Rafael Pérez y Pérez of the Universidad Autónoma Metropolitana, México translated from the original Spanish by Paul Curzon, Queen Mary University of London

(From the archive)

Mexican deity Quetzalcoatl
Image by Alexa from Pixabay

Divinity, all the gods and all the forces that man fails to understand, are sources of inspiration, a supreme gift which can be introduced in the heart or movement of men to make them a yoltéotl, a “heart deified”. (Miguel León-Portilla, The Old Mexican, Mexico: FCE, 1995 page 180)

Part I

Allow me a moment, Your Excellency. Now that I’m older, it’s hard to remember. But don’t worry, I will tell the whole story so that your priests can record it.

It all started that afternoon, on the day of Huey Tozoztli, just before the celebration to the maize goddess Centéotl. On the horizon you could see large pools of blood – the result of the endless struggle of the gods maintaining order in the cosmos – which, when mixed with the clouds and rays of sunshine on the background blue of the universe, drenched the sky with reddish, orange and yellow. As usual, I spent most of my free time watching everything that went on in Tlatelolco market.

What most caught my attention amongst that huge convergence of smells, sounds and forms were grasshoppers; not only lovely to eat roasted on a tortilla, but also alive and full of dynamism, sometimes in the air and sometimes on the floor, sometimes in flight and sometimes sluggishly bound to the Earth – watching me. I was mesmerised for hours. I would line them up in rows of three insects, each row identified by a symbol and each grasshopper with its own number. I then watched the various patterns that arose when some reacted and tried to flee, “grasshoppers 1 and 3 in the first row jumped, while grasshopper 2 did not move.” Sometimes they were impossible to control!

That afternoon I came across Donají, the daughter of a famous Jaguar Knight. She wore a shawl across her shoulders so that you could barely see the long necklace of seashells hanging from her neck that, all tangled up, reached to just above her ankles. To see her made my heart begin to beat so, so fast! Although it was not the first time I had seen her, I had never had the opportunity to introduce myself. I stood beside her, but my mouth failed to produce a sound. No doubt she noticed my nervousness. I spent anxious moments just stuttering, until I said, ‘I’m Tizoc’. A grin spread across her face and she continued on her way without a word. She had ignored me! I felt humiliated. Who was Donají to treat me that way! I wanted to run and hide. Despite her arrogance, I felt a great attraction to her; I promised that one day I would show her who Tizoc really was and how wrong she was to treat me that way.

Part II

Several moons passed when one morning I woke up to hear a terrifying story: Donají had been kidnapped by a thug who was sentenced to death! A search was immediately organised, directed by her father, the great Jaguar Knight, which everyone joined. Eight units were formed. I was assigned to the group that went to Coyoacan. Once there, the warrior commanded us to spread out throughout the area in pairs to speed the search of the area. Because of my youth and inexperience I was appointed as an assistant to Sayil, a retired warrior of the Mexican army. We spent the first night by a stream. While looking for some dry branches to make a fire, I kept wondering how Donají would be feeling. After eating some fruit and roasted snake, I decided to distract myself and I started to enjoy my favourite pastime: watching the world! I was absorbed by a group of fireflies: while flying they would disappear without a trace only to then appear from nowhere. They formed groups of flying dancers in the darkness, following the rhythm of imaginary drums with lit torches plugged into their bodies. It seemed like a ceremony executed by priests in honour of some deity. I was completely immersed in my thoughts, admiring the ritual, when I discovered something surprising: fireflies and crickets share an essence! Grasshoppers jump or stand still on the ground; the flying fireflies were lit or unlit. In both cases, part of their behaviour can be described in terms of two states: jumping or landing; lit or unlit. It was what the priests called the divine essence! I was completely absorbed in my thoughts, when a voice interrupted me:

– ‘Tizoc, are you all right?’, asked Sayil.

– ‘I’m watching the fireflies: I want to see what they can communicate to me’, I replied.

– ‘Communicate?’

– ‘See how some fireflies are lit and others are off. Imagine that if two fireflies flying next to each other are on. We are receiving the message: ‘We are happy’. Now, imagine that we have three fireflies, one lit, then another lit but the third not lit. They are wanting to confess to us: “Walk to the lake and you will find a basket full of cocoa”. We both laughed. I continued: ‘We should call this “the behaviour of the two states.”‘

– ‘I once saw a fortune-teller use the same method’, commented Sayil yawning. I listened intently. ‘He had three figurines made of opossum bones representing Tlahuizcalpantecuhtli, the malevolent God of Venus, who fires darts both at people and at other objects, causing bad things to happen. People asked the fortune-teller questions like “Will the harvest be good this year?” Then he put the figurines in a jar and tossed them: he predicted the future based on how many landed on their back and how many fell on their front – or in terms of fireflies, how many were lit and how many unlit – together with the order in which they fell.’

Sayil’s words left me paralysed for a moment: the priests communicated with the deities through messages made of patterns represented as two states! I was excited and shouted:

– ‘I knew that the grasshoppers and fireflies were connected with the gods!’

Sayil didn’t really understand what I was saying, and he was too tired to ask. A few minutes later he fell asleep, though I only went to sleep late in to the night.

Very early the next morning we continued the search. In some thickets we found the necklace of seashells that I had seen Donají wearing in the market. After a while we came to a crossroads; Sayil, despite all his experience, was not sure which way to turn. So I suggested:

– ‘Let’s ask the gods which path is the right one’.

– ‘What do you mean?’

I pulled out a small leather pouch containing three round stones, which the night before I had painted on one side with green dye made from vegetable plants. I had left the other side its natural grey colour. I put them into a jar and threw them so they landed in a line and said:

– ‘If the green painted side is facing up, it is equivalent to a firefly turned on. If the grey side is exposed it is equivalent to an off’.

– ‘You want to play the soothsayer? We don’t know how to interpret the gods!’

– ‘But we can ask them to guide us’, I said.

– ‘How?’ The warrior asked impatiently.

– ‘Assign to each of the five directions of the universe, a pattern in the stones. Implore the gods for their advice and throw them. I am sure the pattern representing the direction that arises will give us the correct way to go. It is the same as it was when the soothsayer asked about the harvest.’ Sayil didn’t seem to understand my idea, so I continued saying: ‘the combination of stones grey-grey-grey represents the centre, that is, stay where we are. Grey-grey-green means walking towards where the nomadic people are, to the north. Grey-green-grey means walk towards the Zapotec lands in the South. Grey-green-green, means walk to where Tonatiuh, the Sun God emerges, and green-grey-grey means walk in the opposite direction.

I clearly remember that Sayil thought this seemed a silly idea. However, time was short and we didn’t have another way to decide which road to take. So, rather than do nothing he decided to go with my idea:

– ‘How will we know how many steps to go?’ He asked now even more impatiently.

– ‘Once we know the direction we go back to throwing stones. There are eight possible patterns.’

– ‘How do you know?’

– ‘Believe me. I spent a long time watching the grasshoppers jumping! Each pattern represents a number from zero to seven. Then, if we get the pattern 0 we move 20 steps; if pattern 1 appears move 40 steps; if 2 appears we move 80 steps, and so on.

– ‘Tizoc, I think you’ve lost your mind’, Sayil said desperately.

– ‘Trust me. So the first throw will be a statement that tells us where to walk. The second will tell us the number of steps forward. We continue doing this until the instruction appears as the green-green-green pattern, which will mean we have received all the directions.

I put the pebbles in a jar, prayed to the gods for help and threw:

– ‘Grey-green-grey. We have to move towards the land of the Zapotecs! Now, let’s see how many steps: green-green-green, it means …2,560 steps’. I went back to throwing the stones: ‘then we head towards where Tonatiuh rises and walk … 640 steps’.

– ‘Tizoc, are you going to spend all morning throwing stones while Donají is about to die? When are you going to finish this?’

– ‘When the gods tell me to.’

I threw the stones again and to Sayil’s surprise the green-green-green combination appeared: end of the message! We followed the instructions sent by our gods and even though I hadn’t been able to make Sayil believe, we did finally find the hideout of the kidnapper.

Donají was inside a small cave whose entrance was blocked; on seeing her my heart began to pound! Unfortunately, a surprise awaited us, we saw that the kidnapper had two accomplices: this complicated things greatly as we would need support for the rescue. We decided Sayil would go for help while I stayed to monitor the situation, so without wasting more time my partner set off.

Near dark I tried to get as close as possible to let Donají know that she would soon be rescued; I was sure she would be glad of my presence. Unfortunately, one of the thugs discovered me. I was immediately thrown into the cave:

– ‘What are you doing here?’ She asked, shocked to see me.

– ‘Donají! Don’t worry; help will be here soon’, I replied, stuttering again! She immediately realised that there was no else out there to rescue us. Her face contorted in anger and she shouted:

– ‘Why didn’t you go in search of my father instead of getting caught!’

She burst into a flood of tears, weeping and weeping for a long time until she finally fell asleep. I felt a failure. But I swore by the gods to get her out of there!

I tried to stay calm when the three thugs approached: first the leader, who was very young; then a burly one, who seemed a bit of an idiot; and finally a slave who, I suppose, had simply taken the opportunity to get away. The idiot and slave dragged me out of the cave and tied me by my wrists to a tree branch. The noise woke up Donají. I was very scared. The leader began to punch me in the stomach. He wanted to know how many people knew the hiding place. I will never give him the information he wants I told myself. He repeatedly punched me until he grew bored. Then he took a leg of venison, clutching the hoof tightly with both hands he crashed it into my nose! I thought I would die! Donají screamed desperately until finally they took me back to the cave.

From the twisted material of her shawl she made presses and bandages. She wiped my face carefully and all my wounds trying to stem the bleeding. She spent the whole night giving me water to drink and mopping my brow. I will never forget her courage and fortitude! Unfortunately, the next morning, things got worse:

– ‘Tizoc, we have to get up.’

– ‘Are we leaving? Where are we going?’

– ‘I overheard them say that we will go to a valley that is a half-day along the path to Totolhuacalco. The sky is cloudy, so surely it will rain later. If we start today, there is no way anyone will work out where we have gone.’

The situation was critical and I had to come up with something before we left …

Part III

The next day, we were already installed in the new hideout, watching our new surroundings when Donají asked:

– ‘What are your thinking about, Tizoc’?

– ‘The gods have sent me a vision’, I answered.

– ‘A vision? What do you mean?’

– ‘Listen: today, at dawn, Sayil arrived with reinforcements to our former hideout, but was surprised to find it abandoned. Now how could he find us? The rain had washed away all traces of our departure. How would he explain to the great Jaguar Knight that he had lost the trail of his daughter? Sayil and the others, now desperate, reviewed the surroundings and, entering the cave where we had stopped, discovered some strange signs.’

– ‘Do you mean the symbols you drew on the wall?’

– ‘That’s right! One of the soldiers said “It looks like a big fly”. Sayil immediately understood the meaning of the drawings and shouted “No, it’s a firefly!”‘

– ‘What are you talking about?’ Donají asked confused.

At that moment we heard loud cries and Sayil, along with a group of Mexica warriors, began the attack on the new hideout. The slave tried to flee, but was captured immediately; the idiot resisted, but the warriors took a stone and split his head in two; the leader tried to attack Donají, but Sayil grabbed him and strangled him. In just a few moments it had all ended for the trio! Donají wept with happiness. My plan had worked! I was ecstatic! I had finally shown to Donají my worth! It was an unforgettable day for me.

How did they find us? Let me explain, Your Excellency, just let me drink a little water … thank you. It all happened as follows. That day I had to devise a way to communicate to Sayil where we were being taken. I was well aware that our lives depended on it, but was paralysed. Unexpectedly, I heard what I thought was a message from the gods: grasshoppers singing! Two states! That was the solution! I estimated the number of steps required to travel half a day along the Totolhuacalco path and using the same code that Sayil and I had used to find Donají, I left the approximate position of our new location on the cave wall! The kidnappers never suspected that those drawings were instructions of how to find us. So Sayil was given the key to finding us! … Thank you, Your Excellency! I know it was ingenious. Thank you very much. Am I sorry? … What do you mean? “What happened to Donají?”… Your question opens old wounds. I think that you and your brothers would never understand what I mean when I say that, although I never saw her again, my heart was forever linked to hers. I’m tired. With your permission, I would like to go to sleep now.

Two states: divine essence! What can they teach us? What wonders can man create with them? Because while enduring the fifth sun, hearts will be deified. (Tizoc)

The End.

More on …

Related Magazines …


EPSRC supports this blog through research grant EP/W033615/1. 

Lego computer science: What is computation? (simple cellular automata)

Continuing a series of blogs on what to do with all that lego scattered over the floor: learn some computer science…what is computation? Using binary.

We’ve been focussing on representing data so far but data on its own doesn’t do a lot. It is when you combine it with computation that things get exciting and suddenly you have something that can change the world. But what is computation? We will start to explore computation using something called cellular automata. They are just one simple way to do computation (of many).

We have seen that a data representation is just a way of storing information using symbols. It just gives meaning to otherwise arbitrary symbols. Those 1s and 0s, red blocks and blue blocks, Xs, Vs and Is could mean anything. Indeed at different times they mean different things: sometimes a particular group of 1s and 0s stand for a number, sometimes the colour of a pixel, sometimes a letter. So symbols become interesting when we give them meanings (and that is an important point to remember).

Computation is also about symbols, but about manipulating them using sets of rules. What do the rules do? Given one or more symbols they tell you to swap those symbols for new symbols. To do computation you just repeatedly apply a given set of rules, starting with some starting symbols and the symbols change and then change again and then change again …

Elementary Cellular Automata

Cellular automata are just a particular kind of rules that apply to grids of symbols (called cells). They were invented by one of the great original computer scientists, John von Neumann along with Stanislaw Ulam in the 1940s.

Elementary cellular automata, which we will look at here, are a simple version where you just have a row of cells (so a row of symbols). There are only two symbols allowed, usually 1 and 0. We will of course use lego blocks as our two symbols instead: a red brick for 1 and a blue brick for 0. A particular row of red and blue bricks is called the state. The rules change the colour of the bricks in the row and so change the state of the cellular automata. Here is an example state of such a ‘machine’ where the rows are 16 bricks (symbols) long (essentially the memory of the machine will be 16 bits long):

An initial state in lego bricks: a pattern of red and blue bricks.
An example cellular automaton state consisting of 16 symbols. Traditionally cellular automata have symbols 0 and 1. We use a red block to mean a 1 and a blue block to mean a 0. Image by Paul Curzon

Rules

One rule RED-B:LUE-BLUE -> RED
A rule that says if we have RED-BLUE-BLUE then change the middle cell to a RED block.
Image by Paul Curzon

Now if we are going to do computation, we need rules (essentially a program) to apply that changes the state. The rules of an elementary cellular automaton like this are applied to each lego brick, changing it to a new lego brick. To do so they take the brick on either side into account though. Each rule therefore looks at three bricks at a time and changes (or not) the middle brick.

We can write out the rules using lego bricks too – saying what to do for each pattern of three lego blocks. So we could have a rule that if we have a triple RED-BLUE-BLUE then we change the middle of that triple to RED so that the triple becomes RED-RED-BLUE instead. In lego we could represent this rule as shown right, where we show the new value for the middle cell that changes. (Notice we are now using lego bricks, so symbols, to represent rules: a rule is just data too!)

Now a vital thing about rules for computation is that you MUST give a rule for every possibility. Our above rule only tells us what to do for one of the eight possibilities of those triples of bricks that might occur in each position. We must give 8 different rules, so that whatever pattern we come across we have a rule that says what to do.

Here is one possible set of 8 rules we could use:

A set of rules
A set of rules to define how a cellular automaton will behave.
Image by Paul Curzon

Altogether, there are 256 different possible sets of rules like this.

Notice that we have ordered our rules using a binary pattern of the triples counting from 0 to 7 as a way to make sure we have covered every possible pattern exactly once and to make it easier to find the right rule. We could write then in any order of course. It would make no difference to what the rules do.

Doing Computation

Now to do computation we just apply the rules we have chosen to every position in an initial state – an initial pattern of red and blue blocks. We start at one end of the row and apply the set of rules in each position finding the one that matches the pattern at that position. Once we find the rule that matches that position, we note the new middle block accordingly, then move on to the next position. Once we get to the end of the row, we know what the whole new state for the automaton will be: we have done one step of computation. For the cell at either end of the row, assume its adjacent value off the end is 0 (so blue for us). At every position the rule applies to the original triple of bricks in the current state, not ones changed by rules applied to other positions: the rules are applied to every position at the same time.

The easiest way to do this with lego is to line up a row of red and blue lego blocks as the initial state and apply our rules as above to get a new pattern of red and blue lego blocks placed below it. That new pattern is the new state of the machine, Here is a step as applied to our random state we gave above.

Applying the rules to a random starting state
Image by Paul Curzon

Calculating Number Sequences

We seem to be just replacing patterns by new patterns. Are we doing anything useful? Of course we could give some simple meaning to these patterns. Interpret the pattern as a binary number and what is happening? We are generating a number sequence. To see this use the above rules on a shorter pattern, starting with a single red lego block at the left hand end, with the rest blue. This is the binary for the number 1 (00001). Apply the rules and we get the number 2 (00010). Apply the rules again and the pattern of lego turns into the binary for 5 (00101), then 8 (01000) and then 20 (10100) and so on…

The series of transformations through binary patterns from applying the rules.
Image by Paul Curzon

We have created a machine that does a calculation on a number to create a new number. Let it run and it calculates the whole number sequence. Different rules will compute different number sequences: some perhaps more interesting than others.

Images from numbers

If you think numbers are a bit boring, then instead just give a different meaning to the patterns – as giving the colour of pixels, with each new state giving the next row of an infinite lego pixel picture. Now our rules are generating art. Each rule set will compute a different image as will different starting states (again some images generated will be more interesting than others). Here is what our above rules generate if we start with a single red brick in the centre:

The top of a Sierpiński triangle as generated in lego bricks from out rules.
The image generated by our rule if we see it as rules to generate the next line of a lego art image.
Image by Paul Curzon

This is actually a fractal pattern called the Sierpiński triangle. It contains the same triangular pattern over and over again, and If you create a massive version of it on a large lego board you will see that each triangle has the same pattern within it. It is a beautiful recursive pattern.

Sierpiński triangle Image from Wikimedia CC BY-SA 3.0

Apply the rules and create a Lego pixel version yourself.

Explore the different rules

Stephen Wolfram has exhaustively explored all the elementary cellular automata, categorising them and describing their properties. However, that is no reason not to explore them yourself, whether with lego, on graph paper or by writing a program to apply the rules for you.

Of course you do not have to stick to only automata with 2 symbols. Add more symbols / colours of lego blocks (so you will need lots more rules in each set) and explore some more.

There is one cellular automaton, so one rule set (with only two symbols) that is very intriguing. It turns out that, rather than just generate a particular number sequences or pattern as the one above does, it can do absolutely any computation – it is a general purpose machine that can do anything that a modern computer can do…but that is another story.

More on …



Lego Computer Science

Part of a series featuring featuring pixel puzzles,
compression algorithms, number representation,
gray code, binary, logic and computation.

This post was funded by UKRI, through grant EP/K040251/2 held by Professor Ursula Martin, and forms part of a broader project on the development and impact of computing.

QMUL CS4FN EPSRC logos

Lego computer science: binary

Continuing a series of blogs on what to do with all that lego scattered over the floor: learn some computer science…how do computers represent numbers? Using binary.

We’ve seen that numbers, in fact any data, can be represented in lots of different ways. We represent numbers using ten digits, but we could use more or less digits. Even if we restrict ourselves to just two digits then there are lots of ways to represent numbers using them. We previously saw Gray code, which is a way that makes it easy to count using electronics as it only involves changing one digit as we count from one number to the next. However, we use numbers for more than just counting. We want to do arithmetic with them too. Computers therefore use the two symbols in a different way to Gray Code.

With ten digits it turned out that using our place-value system is a really good choice for storing large numbers and doing arithmetic on them. It leads to fairly simple algorithms to do addition, subtraction and so on, even of big numbers. We learnt them in primary school.

We can use the same ideas, and so similar algorithms, when we only allow ourselves two digits. When we do we get the pattern of counting we call binary. We can make the pattern out of lego bricks using two different colours for the two digits, 1 and 0:

Binary in red and blue lego bricks
Numbers in binary where 0 is a blue brick and 1 is a red brick
Image by Paul Curzon
How lego binary turns into place values.
The red bricks (binary 1) in different columns represent different values (1, 2 or 4)
Image by Paul Curzon

Place-value patterns

The pattern at first seems fairly random, but it actually follows the same pattern as counting in decimal.

In decimal we label the columns: ones, tens, hundreds and so on. This is because we have 10 digits (0-9) so when we get up to nine we have run out of digits so to add one more go back to zero in the ones column and carry one into the tens column instead. A one in the tens column has the value of ten not just one. Likewise, a one in the hundreds column has the value of a hundred not ten (as when we get up to 99, in a similar way, we need to expand into a new column to add one more).

In binary, we only have two digits so have to carry sooner. We can count 0, 1, but have then run out of digits, so have to carry into the next column for 2. It therefore becomes 10 where now the second column is a TWOs column not a TENs column as in decimal. We can carry on counting: … 10, 11 (ie 2, 3) and again then need to carry into a new column for 4 as we have run out of digits again but now in both the ONEs and TWOs columns. So the binary number for 4 is 100, where the third column is the FOURs column and so a one there stands for 4. The next time we have to use a new column is at 8 (when our above sequence runs out) and then 16. Whereas in decimal the column headings are powers of ten: ONEs, TENs, HUNDREDs, THOUSANDs, …, in binary the column headings are powers of two: ONEs, TWOs, FOURs, EIGHTs, SIXTEENs, …

Just as there are fairly simple algorithms to do arithmetic with decimal, there are also similar simple algorithms to do arithmetic in binary. That makes binary a convenient representation for numbers.

I Ching Binary Lego

We can of course use anything as our symbol for 0 and for 1 and through history many different symbols have been used. One of the earliest known uses of binary was in an Ancient Chinese text called the I Ching. It was to predict the future a bit like horoscopes, but based on a series of symbols that turn out to be binary. They involve what are called hexagrams – symbols made of six rows. Imagine each row is a stick of green bamboo. It can either be broken into two so with a gap in the middle (a 0) or unbroken with no gap (a 1). When ordered using the binary code, you then get the sequence as follows:

The I Ching version of binary
Binary using the I Ching patterns. Imagine the green rows as stalks of bamboo. A broken stalk (so with a gap) is a 0, An unbroken stalk is a 1.
Image by Paul Curzon

Now each row stands for a digit: the bottom row is the ONEs, the next is TWOs, then the FOURs row and so on.

Using all six rows you can create 64 different symbols, so count from 0 to 63. Perhaps you can work out (and make in lego) the full I Ching binary pattern counting from 0 to 64.

Binary in Computers

Computers use binary to represent numbers but just using different symbols (not lego bricks or bamboo stalks). In a computer, a switch being on or a voltage being high stands for a 1 and a switch being off or a voltage being low stands for 0. Other than those different symbols for 1 and 0 being used, numbers are stored as binary using exactly the same pattern as with our red and blue bricks, and the I Ching pattern of yellow and green bricks.

All data in a computer is really just represented as electrical signals. However, you can think of a binary number stored in a computer as just a line of red and blue bricks. In fact, a computer memory is just like billions of red and blue lego bricks divided into sections for each separate number.

All other data, whether pictures, sounds or video can be stored as numbers, so once you have a way to represent numbers like this, everything else can be represented using them.

– Paul Curzon, Queen Mary University of London

More on …



Lego Computer Science

Part of a series featuring featuring pixel puzzles,
compression algorithms, number representation,
gray code, binary, logic and computation.

This post was funded by UKRI, through grant EP/K040251/2 held by Professor Ursula Martin, and forms part of a broader project on the development and impact of computing.

QMUL CS4FN EPSRC logos