Introduction - TBSHS
Computer Science A Level – Bridging Unit TOC \o "1-3" \h \z \u Introduction PAGEREF _Toc40335463 \h 3C# Programming PAGEREF _Toc40335464 \h 4Getting Started PAGEREF _Toc40335465 \h 4Data Types & Variables PAGEREF _Toc40335466 \h 4Variable Names PAGEREF _Toc40335467 \h 5Constants PAGEREF _Toc40335468 \h 6Comparison Operators PAGEREF _Toc40335469 \h 6Arithmetic Operators PAGEREF _Toc40335470 \h 7Programming Tasks A PAGEREF _Toc40335471 \h 8Selection PAGEREF _Toc40335472 \h 9Programming Tasks B PAGEREF _Toc40335473 \h 12Count-Controlled Iteration PAGEREF _Toc40335474 \h 13Programming Tasks C PAGEREF _Toc40335475 \h 14Condition-Controlled Iteration PAGEREF _Toc40335476 \h 16Programming Tasks D PAGEREF _Toc40335477 \h 18Extra Reading PAGEREF _Toc40335478 \h 18Data Representation PAGEREF _Toc40335479 \h 19Pure Binary PAGEREF _Toc40335480 \h 19Binary Question A PAGEREF _Toc40335481 \h 20Binary Addition PAGEREF _Toc40335482 \h 21Binary Question B PAGEREF _Toc40335483 \h 21Two’s Complement PAGEREF _Toc40335484 \h 22Binary Question B PAGEREF _Toc40335485 \h 22Binary Subtraction PAGEREF _Toc40335486 \h 22Binary Question C PAGEREF _Toc40335487 \h 23Binary Multiplication PAGEREF _Toc40335488 \h 23Binary Question D PAGEREF _Toc40335489 \h 23Fixed Point Binary Fractions PAGEREF _Toc40335490 \h 24Binary Question E PAGEREF _Toc40335491 \h 24Hexadecimal PAGEREF _Toc40335492 \h 25Hexadecimal Question A PAGEREF _Toc40335493 \h 26Extra Reading PAGEREF _Toc40335494 \h 27Digital Logic PAGEREF _Toc40335495 \h 28Logic Gates PAGEREF _Toc40335496 \h 28Flip Flop PAGEREF _Toc40335497 \h 31Half Adder PAGEREF _Toc40335498 \h 32Full Adder PAGEREF _Toc40335499 \h 322 Bit Adder PAGEREF _Toc40335500 \h 33Logic Gates Questions A PAGEREF _Toc40335501 \h 34Further Reading & Activity PAGEREF _Toc40335502 \h 35Logic Problems PAGEREF _Toc40335503 \h 36Problem Solving PAGEREF _Toc40335504 \h 36Logic Puzzles Tasks PAGEREF _Toc40335505 \h 36More Puzzles PAGEREF _Toc40335506 \h 37Thinking Like A Computer Scientist PAGEREF _Toc40335507 \h 38Sudoku PAGEREF _Toc40335508 \h 38Twisty Puzzles PAGEREF _Toc40335509 \h 38Electronics & Microcontrollers PAGEREF _Toc40335510 \h 38Write Programs PAGEREF _Toc40335511 \h 38IntroductionThe aim of this document and these tasks is to help you prepare for the A level. There is a mixture of reading, practical exercises and written questions to help you to consolidate and extend the knowledge you have gained at GCSE.Well over half of the A level is concerned with programming and programming techniques. That is the most important part of this document and the part you should concentrate on completing. Complete as many of the tasks as you can. The other sections are optional but will help you to make a flying start on the course.Our main programming language for the A level is C#. Most of you will have already learned how to program to a reasonable standard in another language like Python or Visual Basic. The learning journey is far shorter when you start your next language. Don’t worry if you find these tasks hard at first. Keep plugging away and trust yourself to get there in time.In order to program in C#, you will need to install Visual Studio Community Edition. This is free to use and is packed with features. If you are using a Mac or have a Linux operating system, you can install .NET Core or look for the Mono Project. Both are free to install but do have some minor differences from the code shown in this document. You should be able to adjust enough to get what you need from these activities.Take the trouble to store all of your programs with sensible names. It will help you later to use them as a reference.There is a lot of code in this document. If you hide spelling errors, it will be easier to read. There is a block of explanation to start with followed by some tasks to complete. You can, of course, do more programming for each section or overall than is included here. Some of the explanations and tables are copied from OCR’s programming reference for C#.C# ProgrammingGetting StartedFor most of your work, you need to write console programs. You will learn how to write applications with a GUI during the course but the bulk of the work involves writing for the console.When you choose to make a new console program, you will see some generated code, something like,Unless you are creating a subroutine or declaring a global variable, you write your code where the red box is.Data Types & VariablesIn C#, variables have a fixed data type. In languages like Python, you can use a variable without first declaring it and can choose to store different types of data with it after you first define it.Neither of those things are possible in C#. Before you can use a variable, you must declare it and you must decide the data type to use. You have a lot of choice.Data TypeRangebyte0 .. 255sbyte-128 .. 127short-32,768 .. 32,767ushort0 .. 65,535int-2,147,483,648 .. 2,147,483,647uint0 .. 4,294,967,295long-9,223,372,036,854,775,808 .. 9,223,372,036,854,775,807ulong0 .. 18,446,744,073,709,551,615float-3.402823e38 .. 3.402823e38double-1.79769313486232e308 .. 1.79769313486232e308decimal-79228162514264337593543950335 .. 79228162514264337593543950335charA Unicode character.stringA string of Unicode characters. 2 bytes per character.boolTrue or False.Variable NamesThere are some basic rules with variable names in C#:the first letter of a variable must be either a letter, underscore (_) or the @ symbol.after this, they can be any combination of letters, underscores or charactersthey can only be one wordthey can only use letters, numbers and underscores (_)hyphens are not allowed (-)spaces are not allowedthey can’t begin with a numberspecial characters are not allowed such as $ or ‘.Remember:variable names are case sensitive, SPAM and spam are different variablesit is convention to use a lower case letter at the start of a variable nameyou can use camelCase or not_camel_casea good variable name describes the data it containsthe variable type always comes before the variable name in C#.In the following, notice how the data type comes first.int parrotAge;const string parrotStatus = "Alive";C# requires you to declare the variable type at the same time as the variable name.However it does not require you to assign a value to the variable straight away.We can use the keyword const to ensure that parrotStatus cannot be changed during runtimeint parrotAge;string parrotStatus = "Alive";parrotAge = 12;Console.WriteLine("The parrot is currently " + parrotAge + " and is " + parrotStatus);Once assigned you can use the variable with other values or variables as shown.Note that if you leave the variable ‘null’ when you declare it, you must assign a value to the variable first before being able to carry out further operations on it. parrotAge = parrotAge + 1;Console.WriteLine(parrotAge);A variable can be overwritten with a new value at any time. You cannot assign data to a variable of different types. Each variable will only hold the data type defined.As you can see – an error is shown in the IDE as "two" is a string, and we are trying to assign it to an ‘int’.ConstantsConstants don’t change after they have been defined.const int ParrotAge = 0;The keyword for declaring a constant is const. It is used BEFORE the data type and declaration of the variable.If you try to use the keyword const and do not declare a value to the variable, then it will throw an error! As you can see – there is a warning line at the semi colon.Remember a constant cannot have a new value assigned to it during run time. The purpose of a using a constant is to provide a word to use in place of a value which you might change before running the program or which is hard to remember. C# programs are compiled before execution. When a program using constants is compiled, every time the constant appears, the compiler replaces it with the value of that constant.Variables have a cost in memory usage, constants do parison OperatorsIf you are a Python programmer, these are not new to you. Visual Basic programmers need to get used to the ==. This is to ensure that comparison and assignment operators are different in the language.==Equal to!=Not equal to<Less than<=Less than or equal to>Greater than>=Greater than or equal toWhen using Logical Operators, the answer to a comparison is always TRUE or FALSE (i.e. a Boolean result. Have a look at what happens with the following code, and results:int valueA = 23;int valueB = 15;Console.WriteLine(valueA == valueB);Console.WriteLine(valueA != valueB);Console.WriteLine(valueA < valueB);Console.WriteLine(valueA <= valueB);Console.WriteLine(valueA > valueB);Console.WriteLine(valueA >= valueB);You can also save these results as a variable.int valueA = 23;int valueB = 15;bool myResult = false;myResult = valueA != valueB;Console.WriteLine("My Result = " + myResult);Arithmetic Operators+Addition e.g. x=6+5 gives 11-Subtraction e.g. x=6-5 gives 1*Multiplication e.g. x=12*2 gives 24/Division e.g. x=12/2 gives 6NB Using integers will result in DIV being applied%Modulus e.g. 12MOD5 gives 2Math.Pow(A, b);Exponentiation e.g. Math.Pow(3, 4) gives 81Note: both numbers need to be double for this to work.Examples of Arithmetic operators:int valueA = 23;int valueB = 15;Console.WriteLine(valueA + valueB);Console.WriteLine(valueA - valueB);Console.WriteLine(valueA * valueB);Console.WriteLine(valueA / valueB);Console.WriteLine(valueA % valueB);double result, number1, number2;number1 = 2;number2 = 2;result = Math.Pow(number1, number2);Console.WriteLine(number1 + " ^ " + number2 + " = " + result);C# does not have an operator or keyword for integer division. In Python, you use a double slash (floor division), Visual Basic does a backslash. In C#, using an integer data type means that you will get results that are integers, with the rounding going down.Programming Tasks AType up the following example program. Notice where it fits in the generated code. Watch the screen as you type, the IDE (integrated development environment) is helpful to you when you program.Press F5 to compile and run the program. Things to notice include,How the variables are declared.How the prompt is created using Console.Write (no line break at the end).How the input is received. Input at the console is always text. It needs to be converted. C# has stricter data type control than other languages and will not do the work for you as Visual Basic would.How the output of the result is done.1.Change the program so that itsubtracts the second number from the firstmultiplies the numbers togetherdivides the first number by the second2.Write a program to perform a conversion between Celsius and Farenheit.3.Program a system which takes as inputs, The length of the base of a triangle. The perpendicular height of the triangle. The system will output the area of the triangle. 4.Program a system which takes as inputs, The average speed of a car over the length of a journey. The distance that the car has to travel. The system will output in minutes the length of time that the journey will take. 5.Program a system that takes the three inputs required to calculate the area of a trapezium and outputs the area.SelectionThere are two commonly used selection constructs in C#. There is an IF statement and a SWITCH statement.You can also use the following logical operators,AND: &&OR: ||With an IF statement, the condition is enclosed within brackets. The semi-colon is not used on the line with the condition but is used with the statements inside the curly braces.int duckWeight = 15;int personWeight = 13;if (duckWeight >= personWeight){ Console.WriteLine("Clearly not a witch!");}else { Console.WriteLine("She's a Witch!");}Here the weight of the person is not greater than that of the duck, and therefore the IF statement executes, and the ELSE is skipped.int duckWeight = 15;int personWeight = 34;if (duckWeight >= personWeight){ Console.WriteLine("Clearly not a witch!");}else { Console.WriteLine("She's a Witch!");}Here the weight of the person is greater than the duck. This means that the IF statement is FALSE and does not run. Therefore, the ELSE statement executes by default.Using else if…int duckWeight = 15;int personWeight = 15;if (duckWeight > personWeight){ Console.WriteLine("Clearly not a witch!");}else if (personWeight > duckWeight){ Console.WriteLine("She's a Witch!");}else{ Console.WriteLine("They weigh the same!");}Note the subtle change in logic in the first IF statement with the removal of the ‘=’. Now the first two tests are for greater than. As the weights are the same, it checks both IF statements, which return false, and therefore executes the ELSE statement.Using logical operators…string caster = "witch";string victim = "peasant";bool later = true;string spellCast = "She turned me into a newt";string victimStatus = "I got better!";if ((caster == "witch") && (victim == "peasant")){ Console.WriteLine(spellCast);}63563500- Both conditions here evaluate to true- Therefore the IF statement condition evaluates to true- Thus the IF statement is executedstring caster = "witch";string victim = "peasant";bool later = true;string spellCast = "She turned me into a newt";string victimStatus = "I got better!";if ((caster == "witch") && (victim == "dog")){ Console.WriteLine(spellCast);}Here the IF statement will not execute because the victim is not a dog. BOTH conditions must be true for the IF statement to execute.string caster = "witch";string victim = "peasant";bool later = true;bool lie = true;string spellCast = "She turned me into a newt";string vicitmLies = "We believe you are lying!";string victimStatus = "I got better!";if ((caster != "witch") || (lie == true)){ Console.WriteLine(vicitmLies);}At least one condition is trueTherefore the IF statement condition evaluates to trueThus the IF statement is executedNesting if statements inside each other,if (Case A is true){ #This code will execute if (Case B is true) { #This nested IF code will execute }}else{ Console.WriteLine("They weigh the same!");}Note the change in logic.If Case A is false, the ELSE statement will execute.If Case A is true then any code in that IF statement will run.This will check the NESTED if statement.Case B will ONLY be checked if Case A is true.Case B IF statement code will ONLY execute if both Case A and Case B are true.Programming Tasks B1.Write a program that reads two numbers and examines the relationship between them. Output one of the following messages,A is greater than BB is greater than AA and B are equal2.Write a program to find the two roots of the quadratic equation ax2 + bx + c = 0 using the formula,Use the double data type to store a, b and c and the two values of x. The following pseudocode should help.discriminant ← b * b – 4 * a * cIF discriminant less than 0 THENThe equation cannot be solved with the formula.ELSE IF discriminant EQUAL to 0 THENThere is a single solution to the equation, x=-b2a.ELSEThere are two solutions, , x=-b+b2-4ac2a and x=-b-b2-4ac2a.END IF3.Look at the following page on the Switch statement, . Consider the circumstances in which it might be preferable to use a switch statement instead of an IF.4.There is a third way to do selection. It is called the ternary operator. It is a very compact way to write conditional code. Have a look online to find out how to use it.Count-Controlled IterationC# has a FOR statement. At first glance it appears a little confusing. It is still, in my view, preferable to the range statement in Python.Couting forwards…for (int count = 1; i <= 5; i++){ Console.WriteLine(i);}Here is an example of the FOR loop in action. Our count is defined within the loop itself. We always know this loop will start a 1 and then iterate until the count = 5. When the count ‘i’ reaches 6, the loop will exit as the condition becomes false. int countTo = 0;Console.Write("What number do you want to count to?: ");countTo = int.Parse(Console.ReadLine());for (int i = 1; i <= countTo; i++){ Console.WriteLine(i);} Here we are using a variable within the condition to vary the number of iterations.This means the loop has more functionality:Run 1:Run 2:However, what would happen if the user entered ‘0’ for a number to count to?Counting Down…int countTo = 0;Console.Write("What number do you want to count from?: ");countFrom = int.Parse(Console.ReadLine());for (int i = countFrom; i >= 0; i--){ Console.WriteLine(i);}You can also decrease your counter to reach a certain value.The for loop has the following format,for (a;b;c){Statements to repeat}The a part of the statement is an assignment statement. It is usually used to assign a starting value for the counter.The b part of the statement is a condition. The condition is checked at the start of each iteration to determine whether or not that iteration should take place.The c part of the statement is an assignment statement. It is usually used to increase or decrease the value of the counter. In the examples, you see shorthand being used. When you say ++ after a variable, you mean, ‘add one to it’. You can choose to change the counter by a different amount or perform a different operation.Programming Tasks C1.Messages Write a program that prompts the user for a message and a number. Your program should use a for loop to output the message the number of times that the user requests. 2.TablesWrite a program that prompts the user for a number from 1 to 12. The full multiplication tables should be displayed for that number. For example, User enters 5. 5 x 1 = 5 5 x 2 = 10 Your task here includes a specific format for the output. You must attempt to output the information as described. 3.Sum Of Cubes Write a program that asks the user to enter a number. Use loops in your code to work out the sum of the cubes of all of the numbers from 1 to that number. Sum Of Cubes 3: 1 + 8 + 27 = 364.Fizz BuzzWrite a program which iterates the integers from 1 to 50. For multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".5.Fizz Buzz SumIf we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.6.Special Pythagorean TripletA Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2+b2=c2For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.This is a tricky task. You will need to nest a loop inside a loop. You need a loop to explore all possible values of a, and all of the possible values of b. Since c can be worked out if you know a and b, you won’t need 3 loops.Condition-Controlled IterationA for loop can be said to be an example of count-controlled iteration because the number of iterations depends on counting from a starting number to a target number. In programs, we often want to repeat sections of code until a condition is met or whilst a specific condition holds. This is called condition-controlled iteration.This type of iteration comes in two flavours, pre-tested and post-tested. The two terms are used to describe whether the condition is examined before each iteration or after each iteration. We sometimes choose one over the other depending on whether or not we want at least one iteration to take place.Our pre-tested structure is the while structure.int countTo = 0;int startValue = 0;Console.Write("What number do you want to count to?: ");countTo = int.Parse(Console.ReadLine());while (startValue <= countTo){ Console.WriteLine(startValue); startValue++;}As you can see, we need some extra things to similar a FOR loop with a condition control.We need a value to compare against so that we can get a BOOLEAN resultWe need to increase the ‘counter’ still by using the ‘++’ operator.However, as you can see – the results look identical. The question is: What is more efficient?string myName = "";const string storedName = "Ceredig";while (myName != storedName){ Console.Write("Guess is my name? "); myName = Console.ReadLine();} Console.WriteLine("This is my name!");Here we repeat the user to enter data until it is correct/matches other data, and then allow the program to continue.Our post-tested structure is the do..while loop.bool quit = true;do{Console.Write("Please enter a menu choice: ");}while (quit == false);Here we see that the ‘quit’ Boolean data type (highlighted yellow) is the same in each case.Our check condition is whether or not the variable ‘quit’ is equal to false. If quit is false, then the loop will carry on.Because quit is set to true, quit == false would equate to false and therefore the loop would exit.With a WHILE loop, because we check the condition first, the loop would not run…However, with a DO WHILE loop, because we check the condition AFTER the ‘do’ part, we would get output from the program.bool quit = true;while (quit == false){Console.Write("Please enter a menu choice: ");}DO WHILE RESULT:WHILE LOOP RESULT:The main difference between these structures is whether or not we want to make at least one iteration take place.When using condition-controlled iteration, we need to ensure that a stopping condition can be reached with our programming logic. Although there are ways to break out of iteration structures (break statement) and ways to skip to the next iteration (continue), we can avoid these if we consider our programming logic more carefully.The advantage of this over the old Python classic ‘while true’ is that we end up with code that is easier to read. We can use the beginning or end of the loop to see the condition that needs to be met for it to continue. There is always a trade-off to be made between code that takes longer to write but that makes more sense when read and code that can be written succinctly. In most cases, the extra words in the source code are more useful to you and other programmers.Programming Tasks D1.Euclid’s highest common factor algorithm.Write a program that implements the following pseudocode algorithm.Set numerator variable to what the user enters?Set denominator variable to what the user enters?Set variable a to numerator?Set variable b to denominator?while?a!=b??? If a>b Then??????? Set a to a-b??? End if??? If b>a Then?????? Set b to b-a??? End if?Set?hcf?variable to a?Output?hcf?2.Extend the program from above so that it simplifies a fraction entered by a user.3.Make a guessing game.Write a program that generates a random number between 1 and 100. Allow the user to keep guessing the number until they have guessed the random number. If they enter a number lower than the number generated, tell them that their number is too low. Do the same if they enter a number higher than the number generated. Once they have guessed the number, tell them how many guesses they entered.Extra ReadingThe following pages are a guide to most of the techniques required for C#. There is more on these pages than is included in this document. pages described algorithms for enciphering and deciphering messages using programs. There are some ciphers that are part of the A level course and they have often been used for examination questions in the past. These pages describe the ciphers and offer pseudocode for writing them. even more challenge, there is no substitute for the Project Euler problems. Whilst some of these are quite accessible, they can get very tricky. Ideally a program should take less than a minute to complete. There is usually a mathematical or programming optimisation that allows for a result in less time though. RepresentationData representation was part of the specification for GCSE. It continues to be a topic in the A level specification and is extended a little from the GCSE material. Not all parts of the specification are included here but you can read up about them with a little online research should you wish.Pure BinaryEverything in the computer is represented as a binary pattern. The component that makes modern computers possible is the transistor. We can think of the transistor as a switch, either open or closed. This gives us our values 1 and 0 that form the bits (binary digits) of our binary numbers.The phrase ‘pure binary’ is used to describe a way of representing integers using as many place values as you need. Understanding binary is about appreciating the importance of place value, the concept in Mathematics that allowed you to read and understand numbers when you were a primary school student. For binary integers, the bits and place values are,128643216842UnitsThese are all powers of 2. The units column (or 1s) is 2 to the power of 0. Thereafter, moving to the left, the place values are increasing powers of 2.The rightmost binary digit of a number is the one underneath the units column and is referred to as the least significant bit. The leftmost binary digit of a number is called the most significant bit. The term significant is being used in its mathematical sense here.?Binary?Denary??128?64?32?16?8?4?2?1?4200101010137?10001001From the table above, we can see that the 8 bit binary representation of the denary number 42 is 00101010.The 8 bit binary representation of the denary number 137 is 10001001.Add up the place values which have a 1 beneath them and you see where these values come from.Binary Question AYou may wish to print this. Any number that consists of only 1s and 0s can be assumed to be in binary. All others are denary.1234567891011121314151617181920Binary AdditionBinary addition follows the basic principles of column addition with digits being carried when the ‘limit’ of a column is reached. What changes from denary is that the largest value for a column is no longer a 9 but a 1.This means,0 + 0 = 00 + 1 = 1 + 0 = 11 + 1 = 10 (0, carry 1)1 + 1 + 1 = 11 (1, carry 1)In the following example, the binary numbers, 1011 (11 in denary) and 10010 (18 in denary) are added together.When performing binary addition, you must lay your sums out this way. Do not work things out in your head or use any mental methods that you learned in little school. The potential for error is too great not to take care with something that is quite basic.If, when adding numbers together, we end up with a total that needs an additional bit, our calculation has generated an overflow. Binary Question B1.10110000+001000012.10110011+001001013.11001100+010101014.10001101+00101111Two’s ComplementComputers need to be able to represent negative as well as positive quantities. The method used for this is called two’s complement.In denary, when we want to represent a negative number, we simply place a minus sign before it. Binary doesn't work that way.The Two's Complement system is used to represent negative numbers in binary. The system works a bit like a milometer. If the milometer is set at 00000 and is turned back one mile, it would read 99999. A negative binary number always has a 1 as the first bit. This is often referred to as the sign bit.It turns our place value table into,-128643216842UnitsWith 8 bits, we can represent numbers from -128 to 127. When using two’s complement, a negative number always has a 1 for the most significant bit, a positive number always has a 0.There is a simple method to convert between positive and negative numbers and the same method works in both directions.Flip all of the bits.Add 1.Binary Question BConvert the following positive binary integers into negative binary integers using two’s complement form.1.000011112.000111013.010010004.011100005.011001106.01010101You can check your answers using the interactive on SubtractionIn order to carry out binary subtraction, we take advantage of the following equivalence,a – b = a + -bGiven two binary integers, convert the one you are subtracting to two’s complement form and then add it to the one you are subtracting from.In denary, 12 – 6 is the same as saying 12 + (-6). We can use this knowledge to perform subtraction in binary.00110000-00100001Find out the Two’s Complement form of the second number,00100001Flip bits = 11011110Add 1 = 11011111Now add this to the first number.00110000+1101111100001111111We do not carry the last 1 when doing subtraction this way. Let’s check the method,00110000 = 4800100001 = 3300001111 = 1548 – 33 = 15 ?Binary Question C1.01010101 – 000110112.01110000 – 000111013.01010101 – 000110114.01110000 – 00011101You can check your answers using the interactive on MultiplicationTo multiply by 2, shift all of the digits of the binary number one place value to the left. To multiply by 4, shift all of the digits two places to the left.The left and right shift method is fine for multiplying and dividing by powers of two. You really need to use long multiplication, applying the same method that works in denary.For example, 1001 * 01011001xLay the numbers out in columns01011001+Multiply the first number by the rightmost place value of the second.100100Add 0s until next non-zero digit. Multiply the first number by this digit.101101Add together the part results to get the final answer.Binary Question DMake a few questions of your own to do. Use the Windows calculator to check your answers by going to Programmer mode and setting the number base to binary.Fixed Point Binary FractionsIf we extend the place values of our binary numbers to the right, we make negative powers of 2, which are fractions. 842Units1/21/41/81/160.50.250.1250.0625This method for representing fractions in binary is called fixed point binary. In order to work out the value of a bit pattern, we need to know the position of the binary point.Binary Question EList all of the binary fractions that can be made if you have 4 bits after the binary point.Bit PatternValueBit PatternValue0000.00010.06250000.00100.1250000.00110.1875At the bottom of this page, , there is a description of a method that can be used to convert a decimal fraction that is not a power of 2 into fixed point binary. Using the method, you will see that there are some numbers that need a small number of place values to represent in denary but that need large or infinite numbers of bits to do so in binary. The number of bits you choose to represent a number is called precision. This term means something slightly different to computer scientists than it does to mathematicians. HexadecimalHexadecimal is Base 16. That means that our place values are powers of 16 and that we can have digits with the value 0-15 in any column. Here are the numbers from 0 -15 in denary, binary and hexadecimal.DenaryBinaryHexadecimal000000100011200102300113401004501015601106701117810008910019101010A111011B121100C131101D141110E151111FNotice that we need 4 bits to make all of the hexadecimal digits for each column. That makes it pretty easy to convert between binary and hexadecimal.Hexadecimal is used as a shorthand for binary. It allows programmers to use a more compact notation when using binary patterns. Since all information in computer systems is stored in binary, the use of hexadecimal makes no difference to storage or memory usage. It does reduce the number of digits to parse for a human reader by giving one hexadecimal digit for every four binary digits (nibble).Hexadecimal Question AHex To Binary1.B3………………………………………6.9F ………………………………………2.E2 ………………………………………7.4D ………………………………………3.F8 ………………………………………8.1A ………………………………………4.A9 ………………………………………9.5D ………………………………………5.7C ………………………………………10.6C ………………………………………Binary to Hex1.00110011…………………5.01101101…………………2.01010101…………………6.11011001…………………3.00011101…………………7.11100011…………………4.11110010…………………8.11110001…………………Extra ReadingA nice, challenging programming task would be to implement the method for converting denary fractions into fixed point binary.The following page describes how floating point numbers are represented on computer systems, this in program code is a significant challenge – only for the brave souls. It is a nice extended task to do if you are looking for ideas.Digital LogicLogic gates were part of the GCSE specification. At A level, we need to add a few more logic gates – important ones as it turns out.We also need to look at some fundamental logic circuits.The way we write expressions for logic gates at A level might be different to the way you had to read and write them at GCSE. You will also learn how to use algebra with the expressions.In this section, you will find diagrams, truth tables and expressions for the main logic gates. You will also see a flip flop, and the adder circuits that are part of the A level specification. There will be some questions using logic circuits at the end of the section.For exploring logic gates and the circuits you can make with them, I still like to use a program that is no longer being actively developed. It is called Logisim and can still be downloaded if you search online (it is a Java program and will need a Java runtime environment on your machine). The diagrams in this document were produced with that program. You can also create interactive logic circuits using a lot of online simulators directly in your browser.Logic GatesAND GateABQ000010100111In this circuit, both inputs A and B need to be set to 1 for the output Q to be a 1.The expression for this circuit is Q=A.BOR GATEABQ000011101111In this circuit, either input A or B (or both) need to be set to 1 for the output Q to be a 1.The expression for this circuit is Q=A+BNOT GATEAQ0110In this circuit, Q is always the inverse of A. The expression for this circuit is Q=ANAND GateABQ001011101110NAND means ‘not AND’. Its output is the inverse of an AND gate. It is an important logic gate. All other logic gates can be made out of NAND gates. It is also used in flash memory circuits.The expression for this circuit is Q=A.BNOR GateABQ001010100110NOR means ‘not OR’. Its output is the inverse of the NOR gate. Like the NAND gate, it is used to make flash memory and, using NOR gates only, all other logic gates can be made.The expression for this circuit is Q=A+BXOR GateABQ000011101110XOR means ‘exclusive OR’. You get an output of 1 if either input is a 1 but not both. This turns out to be useful enough for a special gate to exist as you will see with the adders.The expression for this circuit is Q=A BIt can also be written as Q=A.B+A.B when the circuit is constructed using fundamental logic gates.Flip FlopThe D-type flip flop is part of the specification for the A level. You just need to know that it exists and roughly how it works.A flip-flop is made from combinations of logic gates and are used as units of memory within integrated circuits. Flip flops are also referred to as latches, because of the way you work with them electronically.The input D is our data bit. This is the information we want to store. We set that high or low.This circuit uses a rising edge triggered flip flop. The input C is called our clock. When the clock goes from low to high, our data bit is 'clocked in' and the output from the circuit at point Q reflects the value of the data bit we set.The output only changes when the input C is changed from low to high. The edge that is rising is the voltage signal, were you to plot it with an oscilloscope. This means that the data bit that was set, can be read from the output for as long as that bit needs to be stored. This makes it a unit of memory in a logic circuit.There are other types of flip flop (JK is very common).Half AdderThe half adder circuit is a logic circuit which adds 2 bits together and outputs the SUM and the CARRY bits.INPUTSOUTPUTSABSC0000011010101101S= A⊕B S= A.B+A.BC=A.BFull AdderA full adder is a little more complex as a circuit. It is designed to be chained along with other full adders to make circuits which can do addition of more bits.INPUTSOUTPUTSABCinSCout0000000110010100110110010101011100111111Cin = CARRY IN (FROM PREVIOUS ADDER), Cout= CARRY OUT2 Bit AdderThis is a circuit which can add together two 2-bit numbers and report the result. To make an adding circuit, use a half adder for the least significant bit (units). You only need a half adder because there is no carry in on the least significant bit.Each place value thereafter needs a full adder. To add a place value to this adding circuit, C1 is connected as the carry in to the next full adder.Logic Gates Questions A2.A1, A2, B1, B2 and Q are Boolean variables.CDCDa.Construct a truth table for the above circuitA1B1A2B2C(A1 XOR B1)D(A2 XOR B2)Q(C NOR D)0000000100100011010001010110011110001001101010111100110111101111b.Express Q in terms of A1, A2, B1, B2 for the logic gate circuit.NOR = SKIPIF 1 < 0 EOR = SKIPIF 1 < 0 Further Reading & ActivityDownload Logisim or use an online logic simulator to explore the circuits and logic gates mentioned in this section. Make an adder that is capable of adding together two nibbles (4 bit numbers).You can read ahead about Boolean algebra, a topic that you will cover in detail during your course. Don’t worry if it seems confusing when you try to learn it by yourself. It will end up being quite straightforward for you. ProblemsThe ability to solve simple logic puzzles has been part of the specification for some time. At its heart, our subject is about solving problems. Not all problem solving is about programming. Problem SolvingHere are some terms that can be used to discuss problems in general.TermDefinitionGivenThe initial situation - the starting pointGoalThe desired outcome - what you want to achieveResourcesThe things that can be used to reach the goal are that impose constraints on how the goal can be reachedProblemA given where it is not obvious how to reach the goalA problem is well-defined if there is a,clearly defined initial situation,clearly defined goal,clearly defined set of resources and constraints,clear ownership - someone is responsible for arriving at the solution.The last point is really important, not just for the general theory about problem solving but for approaching work in general.We employ a range of strategies when solving problems. One common approach is called decomposition, where we break the problem up into parts that are simple to solve by themselves.Another approach that can work is exhaustive searching. That means that we explore all candidate solutions to a problem before deciding which one or ones provide the true answer.Logic Puzzles Tasks1.Party Time3 friends were on their way to a party. The following facts are true about their clothes,Sally did not wear leather.The person in cotton was wearing yellow or blue.The person in blue wore leather or wool.The person in cotton was Jim or Fred.Sally was not in blue.Fred was in red or blue.Match the person with the colour and material.PersonMaterialColourSallyJimFred2.Whose pet is it?Anita, Ben, Chuck, Debbie, Eliza and Fred each owned a pet. Their pets (not in order) were a parakeet, a cat, a dog, a fish, a parrot and an owl.Eliza's neighbour, who was not Ben, owned a parrot.Fred did not own a flying creature.The parakeet owner lived next to Debbie.Ben did not own a four-legged pet.Both the owl and cat owners lived across the street from Eliza who lived next to the parakeet owner.The owl and parakeet owners lived at the opposite end of the street to Anita and Ben.Work out who owned which pet.ParakeetCatDogFishParrotOwlAnitaBenChuckDebbieElizaFred3.Great GolfersMr Peters, Mr Edwards and Mr Roberts are playing golf. Mr Peters remarks that he has just noticed that their 3 first names are 'Peter', 'Edward' and 'Robert'. "Yes", says one of the others, "I'd noticed that too, but none of us has the same surname as our first name. For example, my first name is 'Robert'".What are the full names of the three golfers?More PuzzlesThe following site is an infinite source of grid-based logic puzzles, Like A Computer ScientistIn addition to the material in this document and the logic puzzles, there are other challenges that can get you into the habit of thinking like a computer scientist.SudokuSudoku puzzles lend themselves to being solved using algorithms. The following site describes specific strategies that you can employ to solve Sudoku puzzles. I have yet to find a Sudoku puzzle in a mainstream newspaper that cannot be solved using only these strategies. completing a puzzle, think about the algorithm you are using to find your next step. Think about the methodical way you scan columns, rows and mini-squares to find places where you can apply each strategy.Twisty PuzzlesI have always found twisty puzzles like the Rubik’s cube to be interesting. As a youngster, I enjoyed the challenge of solving something difficult. As I got older, I learned to appreciate the mathematically and computationally interesting aspects of each of the puzzles. The maths involved in the puzzles and programmed solutions to them can be quite demanding.The following pages describe a number of puzzles, their solutions and some other areas of interest. & MicrocontrollersElectronics is a good way to gain an appreciation of the implications of the hardware at the heart of our subject. It also provides a good context for writing programs.The micro:bit is cheap and can be programmed in Python. There are a lot of ideas on, Arduino is programmed in C++. The syntax and most of the core statements and structures are identical or virtually identical to those you will use in C#.These pages are older but contain some ideas for programming some circuits for Arduinos. ProgramsComputer Science is about programming. Whenever you are faced with a problem or challenge that can be solved with a program, you should be trying to do that.Make programs to solve problems related to your other subject choices for A level, your hobbies or just to annoy your siblings.If you play a game that allows you to write mods, have a go. It’s not as hard as you think to get some kind of result and it gets you thinking like a developer for a while.In short, be a programmer, write programs. ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- independent assessment scrutiny year 7
- edexcel gcse in computer science scheme of work for year
- introduction stellenbosch university
- computer architecture 110
- introduction tbshs
- string tools python
- test bank solution manual text books short answers
- edexcel gcse in computer science lesson activities for
- university of maryland baltimore county
Related searches
- introduction to financial management pdf
- letter of introduction sample
- argumentative essay introduction examples
- how to start an essay introduction examples
- introduction to finance
- introduction to philosophy textbook
- introduction to philosophy pdf download
- introduction to philosophy ebook
- introduction to marketing student notes
- introduction to marketing notes
- introduction to information systems pdf
- introduction paragraph examples for essays