Coding and Logic True Logic is reasoning If someone is using logic in everyday life they are explaining something by following a set of rules Guessing is not using logic Everything that a computer does involves logic A computer cannot guess or be random At its most basic level a computer can only test to see if something is true or false False TruE or False Computers use a number system known as binary The binary number system uses two numbers 0 and 1 Computers only really understand two things their electrical supply being off or on Coders can use these two states to get the computer to test for True or False Yes or No or On or Off Coding tips When coders program computers the computer language they use changes the commands into binary Coders don’t have to know binary but it is helpful to understand the logic behind the two states off or on There’s a joke that says Binary is as easy as 1 10 11 Read the next page and see if you can decode the joke 4
Getting BInary Binary is actually simple to learn Look at the chart below If any numbers have a 1 under them you add those numbers together Here there is 1 under 4 and 1 64 32 16 8 4 2 1 0 0 0 0 1 0 1 4 plus 1 is 5 So 5 in binary is written 0 0 0 0 1 0 1 Can you work out what these binary numbers are using this shorter chart a 2 1 b 2 1 c 2 1 0 1 1 0 1 1 Answers are on page 32 GET Programming How does a computer use True or False to work out logical solutions Coders get the computer to ask a question The answer to that question can only be True or False You have some hens and you want to put their eggs into boxes Each egg box holds six eggs If you have more than six eggs you need a second egg box Question Have I got more than six eggs Answer I have seven eggs True get another box I have three eggs False don’t get another box Can you think of some questions you could ask that would only need True or False answers 5
Following Instructions A computer can only do what it is told to do Code is how we to tell the computer to do things Coders write a set of instructions known as an algorithm The computer is then asked to perform the algorithm What does an algorithm look like An algorithm is just a simple step-by-step list that shows how to do something Feeding the Dog It is important that an algorithm’s steps are in the right order Can you see what is wrong with the order of the code below Can you sort the instructions into the correct order 1 Get can 2 Get can opener 3 Open can 4 Spoon out dog food on 5 Put bowl on kitchen floor kitchen floor Answers are on page 32 6
GET Programming How good are you at writing clear instructions Try to play this game with a friend Make an obstacle course on the floor using cushions Now imagine your friend is a computer-powered robot Write an algorithm telling them how to walk from one end of the course to the other without touching a cushion Use precise instructions such as Walk two paces forward Walk one step left Your friend must follow your instructions EXACTLY They mustn’t try to guess what you meant If they touch a cushion add a point to your score Walk two paces forward Walk one step left Walk two paces forward Walk one step right Walk two paces forward Take turns writing the algorithm and being the robot The one with the least points at the end wins 7