Lesson Objectives: To be able to: - Define the terms bit, nibble, byte, kilobyte etc … - Understand that data needs to be converted into a binary format to be processed by a computer - To be able to convert positive binary to decimal and vice versa Starter Q1) What is binary? Q2) Why do computers use binary? The table below shows measurements for data or you can think of it as capacity. Use Google to help you fill the table below: Bit Nibble 8 bits 1024 bytes 1024 kilobytes 1024 megabyte 1024 gigabyte A bit is equal to a 1 or 0 4 bits 1 kilobyte Binary Conversion Decimal As humans, we use a numbering system called decimal. This numbering system is base 10 which means that each time the number is getting bigger by x10. 10^3 1000 10^2 100 10^1 10 10^0 1 Note: This is the decimal / denary numbering system that we use. Binary Computers use a numbering system called binary. This numbering system is base 2. The reason why computers use binary and base 2 is that it is easier to represent. For example we can represent a positive and negative charge quite easily using circuits. 1 = on or positive 0 = off or negative Conversion guide Decimal to binary The number: 5 1. Draw your 8 bits binary number column 128 0 2. 3. 4. 5. 6. 7. 8. 9. 64 0 32 0 16 0 8 0 4 1 2 0 1 1 Now we are going to ask, will the number 128 fit into 5? If it doesn’t we put a 0 Will 64 fit into fit into 5? It doesn’t put a 0 32? No, 0 16? No, 0 8? No, 0 4? Yes 5 – 4 = 1 2? No, Will 1 fit into 1, yes but a 1 Use the example above to complete the binary conversion below. Worksheet Binary Conversion Cross-Number 1 1 2 3 5 7 6 8 11 9 12 16 18 4 10 14 13 15 17 19 20 Convert denary numbers to binary and binary numbers to denary. If a number consists of 1s and 0s, assume it is binary. Otherwise assume it is denary. Across 1. 254 5. 5 7. 9. 1011 111101 11. 14. 16. 20. 101001 110011 6 131 Down 1. 13 2. 3. 10010 1111000 4. 5. 6. 8. 10. 12. 13. 15. 17. 18. 19. 1100 1010 10000 1110 1111 3 111100 9 4 1010000 11110 Programming Task 1 Every variable has a given data type. You need to explain the different types of variable and what they are used for. The most common data types are: String - ? Integer ? Float - ? Also known as real numbers Boolean – In some languages we have to tell the computer what data type a variable is going to be. Python, on the other hand, is able to decide the data type of the variable according to what value it is first given (or to use the correct term what it is initialised with). This can cause problems when we try to do something with the wrong data type. Task 2 Create a program that uses if statements and operators to test conditions. You could make a program that will ask the person their age and then say whether or not the can purchase learn to drive a car. Task 3 (15) Create a program that will ask the user for the current year and the year she was born. The program should then workout her age i.e. how old she is. Once we know how old she is, we should then be able to find out how many days she has lives, hours, minutes and even seconds. Clues current = int(input("Enter current year")) born = ? days = age * 365 print("The value is " + str(days)) Task 4 (15) We can store text in variables and we can then manipulate that text. To do this we use something called string method. I have put an example below, it is your job to try all of them and explain what they do and find other examples online. Name = “Bob” Print(Name.upper()) The output: BOB String method Description of what it does lower() upper() title() swapcase() capitalize() Can you remember what concatenation is? If not, do a quick search online and make a note of it. Task 5 - Restaurant Tip Write a program. Two people eat dinner at a restaurant and want to split the bill. The total comes to £100 and they want to leave a 15% tip. How much should each person pay? Harder: make the program ask how many people there are, what percentage the tip should be and how much the bill comes to. Save this as Restaurant tip. Task 6 - Restaurant Tip The grade boundaries for a test are: U-0 D – 40 C – 50 B – 60 A – 70 Write a program that asks for a mark and then says what grade it is worth.