Computer Science Higher Must Learn! PDF

Document Details

AdulatoryRiver7999

Uploaded by AdulatoryRiver7999

Ohio State University Agricultural Technical Institute

Tags

computer science computer architecture data representation digital systems

Summary

This document provides an overview of computer science concepts, including topics like ASCII, Unicode, two's complement, floating-point representation, and computer architecture.

Full Transcript

ASCII = American Standard Code for Information Interchange Two’s Complement In two’s complement, the most significant bit (the lefmost bit) indicates whether the number is positive or negative. If the most significant bit is a 1 then it is a negative number, if it is a 0 then it is positive. e.g.,...

ASCII = American Standard Code for Information Interchange Two’s Complement In two’s complement, the most significant bit (the lefmost bit) indicates whether the number is positive or negative. If the most significant bit is a 1 then it is a negative number, if it is a 0 then it is positive. e.g., 1001 1010 = negative number 0001 1010 = positive number Positive numbers are stored as per normal. However, the largest positive value that can be stored in this system would be 127 (0111 1111), as this is the first bit cannot be a 1 if the number is positive. You can also use this shortcut system to work out what a negative number is in it’s two’s complement: Write out the positive number you are looking for Now swap al the 1s for 0s and vice versa Now add 1 on the end The answer will be the sum of these two values Representing Numbers in Floating Point Floating point numbers take the form of: Mantissa x baseexponent And within computers hey are stored as: Sign,Mantissa,Exponent To convert numbers into floating point format, we do four steps: 1. Work out the signed bit for the mantissa. It is 0 for positive and 1 for negative. 2. Use the remaining bits for the rest of the mantissa. 3. Move the binary point so that it sits to the left of the first 1 in the number. 4. Store the movement of the binary point as the exponent. a. Large numbers will have a positive exponent in normal binary b. Small numbers will have a negative exponent in two’s complement Range and Precision of Floating: Point Representation In Floating point format... The Number of bits allocated to the mantissa affects the precision of the number. o If there are more mantissa bits, the precision increases. o If there are fewer mantissa bits the precision decreases. The number of bits allocated to the exponent affects the range of numbers that can be stored. o If there are more exponent bits, the range increases o If there are fewer exponent bits, the range decreases Storing Text in ASCII and Unicode ASCII Unicode (UTF-16) Advantages Less Storage Required More Characters can be represented (65,536) Disadvantages Fewer characters can be More Storage Required represented (256) Bit-mapped and Vector Graphics Bit-mapped Graphics Vector Graphics Advantages Produce more realistic Objects can be layered photographic images Images are scalable Can be edited at pixel without losing level in fine detail resolution/becoming Less constrained by pixelated mathematical objects Individual attributes can be edited Disadvantages Images can become Images can’t produce pixelated/are as realistic an image resolution dependent as bitmaps How Computers Work You turn the computer on. The computer loads data from read-only memory (ROM) and performs a power-on self-test (POST) to make sure all the major components are functioning properly. As part of this test, the memory controller checks all the memory addresses with a quick read/write operation to ensure that there are no errors in the memory chips. Read/write means that data is written to a bit and then read from that bit. The computer loads the basic input/output system (BIOS) from ROM. The BIOS provides the most basic information about storage devices, boot sequence, security, Plug and Play (auto device recognition) capability and a few other items. The computer loads the operating system (OS) from the hard drive into the system’s RAM. Generally, the critical parts of the operating system are maintained in RAM while the computers are on. This allows the CPU to have immediate access to the operating system, which enhances the performance and functionality of the overall system. When you open an application, it is loaded into RAM. To conserve RAM usage, many applications load only the essential parts of the program initially and then load other pieces as needed. After an application is loaded, any files that are opened for use in that application ae loaded into RAM. When you save a file and close the application, the file is written to the specified storage device, and then it and the application are purged from the RAM. The Structure of the CPU The processor is the main part of the computer, consisting of the control unit, the arithmetic and logic unit (ALU) and the registers. The control unit makes sure that the different parts of the CPU act in an organized way. It ensures that the program instructions are carried out in the correct order. A processor is built with several small storage locations called registers. These registers will each be able to hold a binary number. If the processor needs to add two numbers together, it will load these numbers from RAM into two of the processor registers. It will also load the ‘add’ instruction into another register. The ALU will do the calculation. Once the calculation is done, the answer will be sent to a register before being sent out to the RAM. The original numbers and the add instruction in the registers will be overwritten with the next lots of data and instructions. There are two registers we need to focus on specifically, the memory address register and the memory data register. Memory address register (MAR): When data is going to be fetched from RAM, the location needs to be known. The MAR stores the address location o Address bus: The address bus identifies the required address location. Memory data register: This is where data retrieved from RAM is temporarily stored. o Data Bus: The data bus transfers data between the processor and the memory. The Fetch-Execute Cycle: This is the process where an instruction is retrieved from memory, decoded, and then carried out. The processor sets up the address bus with the required address. The processor activates the red line on the control bus. An instruction is fetched from the memory location using the data bus and stored in the instruction register. The instruction in the instruction register is then interpreted by the decoder and carried out. Factors Affecting Computer System Performance Factor How it Affects System Performance Additional processors/cores Instructions can be allocated to different processors Allows simultaneous execution of instructions (parallel processing) Increased cache memory Frequently accessed instruction is held in the cache Access to cache on the chip is faster Reduces the need to access slower RAM storage Increased width of data bus More bits transferred in a single operation Increased clock speed Increases the number of instructions cycles the processor can do per second Environmental Impact Heating Systems: Smart heating systems use a variety of ways to control the amount of heat required in our homes. Using activity sensors, some smart systems learn the temperatures that you prefer in certain rooms and at what times. Monitoring the activity in rooms can mean that the smart system adjusts the heating up or down depending on whether there is unusual activity in the house. The thermostat is connected to wi-fi and can be manually controlled by using an app on your phone. This allows you to turn the heating system off if you are not going home, or to turn it on so that it is at the optimum temperature if you are coming home early. Traffic Control: Vehicles are considered one of the main contributing sources of greenhouse gas. Studies in the European Union showed that transport causes 25% of all carbon dioxide emissions. Vehicles consume greater amounts of fuel when they are constantly accelerating and braking in traffic jams. The optimum speed for low fuel consumption and low emissions is between 45 and 65 miles per hour. Intelligent transport systems use software and hardware along with information and communications technologies, to improve the efficiency of and safety of transport networks. They use a variety of information from cameras and sensors, along with control of traffic signals, to try to keep traffic moving, reducing the amount of harmful emissions. Cars with individual navigation systems use satellite information on traffic flow to guide drivers away from traffic congestion and on to more free-flowing routes. Car management systems A number of different car management systems are used to reduce the impact on the environment. Start-stop systems automatically shut down the engine when the car is not moving – this reduces the amount of time the engine spends idling, reducing fuel consumption and emissions. The car automatically re-starts when the accelerator is pressed, which is most advantageous for vehicles that spend significant amounts of time waiting at traffic lights or frequently come to a stop in traffic jams. Engine control units use sensors to ensure the engine’s air/fuel ratio can be controlled very accurately, ensuring optimum fuel consumption and a reduction of carbon dioxide emissions. Intelligent heating systems can be used to reduce carbon footprints and the environmental impact of homes and businesses. Pro-active decisions making by software reduces usage by: Remote access to control heating when not at home Use of geolocation can automatically turn heating off when no one is home Takes account of external weather forecast and adjusts temperature accordingly Real time temperature monitoring through mobile devices can reduce unnecessary gas/fuel use Data can be analyzed to determine how quickly a home heats and how slowly it loses heat, meaning that the boiler can be used more efficiently Multi room control systems prevent rooms being overheated when not in use Security Risks and Precautions Cookies Tracking cookies are small files that are created by scripts running in web pages. A normal cookie is simply a small file of information that can be used by the web site to personalize its pages the next time the user accesses the site. The tracking cookie is created by an advertising company that has an advert on a web page. If the advert runs on other web pages visited by the same user, the advertiser can track the web pages visited by the user which can be considered a privacy issue. Denial of Service (DOS) attacks A denial-of-service attack is an attack which attempts to prevent a system from operating normally. If the service is a commercial one, then the denial-of-service attack might mean that the service’s ability to continue trading is interrupted. It may mean that customers or clients of the service cannot access the system at all as a result of the attack. An attack such as this could be perpetrated from a single machine. Alternatively, many machines could be used to simultaneously attack the service, in which case the attack is referred to as a distributed denial of service (DDOS) attack. Characteristics of a DOS attack: Symptoms Slow performance Inability to access data Effects Disruption to users and businesses Costs Lost revenue Labour to rectify the fault Type of Fault Bandwidth consumption Resource starvation Domain Name Service (DNS) Reasons Financial Political Personal Digital Signatures A digital signature is a way of officially signing a document. The process makes use of public key decryption. A digital signature is a way to ensure that an electronic message or document is authentic. The signature is created when the message is sent. The sender uses their private key to encrypt their message. The message can only be decrypted using the public key. Anyone can access the public key. However, only the sender has their private key, so the message had to have come from them. Digital Certificates A digital certificate is a way to confirm that a certain public key belongs to the person that is using it. Digital certificates are sold by a Certificate Authority to companies and organizations who provide Internet services that need to be authenticated as genuine. Once a web service has acquired a digital certificate from a certificate authority (CS) tis can then be used to authenticate the web server to clients and to begin the encryption can then be used to authenticate the web server to clients and to begin the encryption process. Web browsers have a lift of CAs built into them which they can use to ensure that the web server’s certificate has been issued by a reputable authority who is able to authenticate. Keys: A public key is used to encrypt data. A private key is used to decrypt data. Certification authorities issue certificates to companies. This means that the site is regulated and so you can trust the digital signature. The Computer Misuse Act: The Computer Misuse Act (1990) recognizes the following as offences: 1. Unauthorized access to computer material. 2. Unauthorized access with intent to commit or facilitate a crime. 3. Unauthorized modification of computer material. 4. Making, supplying, or obtaining anything which can be used in computer misuse offences. Modular Programming Modular Programming from Pseudocode Design When using pseudocode to design efficient solutions to a modular problem, you must include the following: Top Level design – the major steps of the design Data Flow – shows the information that must flow In or Out from each of the subprograms Refinements – break down the design from the top level when required Modular Programming from Structure Diagram Design When using structure diagrams to design efficient solutions to a modular program, you must include the following: Top level design – The major steps of the design Data Flow – Shows the information that must flow In or Out from each of the sub- programs Refinements – Break down the design from the top level into smaller steps. They can be shown separately from the top-level design or below the top-level design Actual and Formal Parameters Parameter passing Parameter passing allows the values of variables in the main program to be passed to subprogram. The value of these variables (or a copy of the value of these variables) is passed as a parameter to sub programs, as necessary. When we formally define a function/procedure (give it a name and describe its code), we must create parameter names. The name that we come up with when formally defining a function/procedure are referred to as formal parameters. The values that are given when a function is called (in the main program) are known as the actual parameters. Def function_name(formal_parameter_1, formal_parameter_2): return ######################################## # main program variable = function_name(actual_parameter, actual_parameter) NOTE: The order that parameters are provided is particularly important! The scope of local and global variables Functions and procedures make use of variables. Variables can be declared as: Global variables Local variables Global variables A global variable is one that is declared in the main program (that is, outside of a subprogram). It can be accessed and used in any part of the program (both inside and outside of functions). As the variable is accessible throughout the whole program, this variable will need a place in RAM for the entire duration of the program. It therefore places a demand on system resources. Local variables A local variable is one that is declared within one specific function/procedure. During the execution of this function/procedure, the values of local variables will be held in RAM. Upon completion of the execution of this sub-program the variable is no longer retained in RAM. This is more efficient in terms of demands on system resources. Scop of variables The scope of a variable means where that variable can be accessed within a program. The scope of a global variable is the entire program (this means that it is always accessible). The scope of a local variable is just within the subprogram where it was declared (so you cannot access this variable outside of the program). Data Type & Structures It is a good idea to be clear on the different terminology used when describing code: Term Examples Data Types Strings, Integers, reals, Booleans Data Structures ID arrays, parallel ID arrays, records, arrays of records Control Structures If statements, loops A single item of information can be stored into a variable. Each item is stored as a particular data type. E.g. Name = “Sally” (a string) Age = 15(an integer) Height = 1.67(a float) Completed = False (a Boolean) However, we can also create data structures which hold more than one piece of information e.g., in National 5 computing science we learned about 1D arrays as a type of data structure. 1D Arrays A 1D array is a simple list. The list has a name. Each item in the list has an index position. e.g., names = [“Bob,” “Jane,” “Fred,” “Barry”] Names = “Bob” If you were asked what was stored in the variable names, you would describe it as a 1D array of strings. In Higher computing, we learn about 2 new data structures. Parallel 1D arrays We may need to store more than one item of information about something. We could opt to store each category in a separate array, with the index positions linking the pairs. The index value in each array is the key to connect the information about everyone. In Python: Names = [“Mary,” “Jane,” “Bob,” “Fred”] Ages = [27, 3, 31, 5] Print (names ) + “, “+ str (ages )) There is no limit to the number of parallel arrays you can use to store information about an object. Parallel arrays work by having multiple items of information about an object (in this case, a person) located in the same index position across the arrays. To set up parallel arrays we need to know: − How many elements are going to be in the array − What data type they are Records An alternative way of keeping many items of information about an object is using a record. A record, in software development, is a user defined data structure that can store multiple pieces of data, which can be different data types. Imagine you are trying to learn properties of chemical elements. You might set up 20 of these blank records cards with headings, so that you can fill in the element information later. The equivalent of planning the structure of these record cards in Python is to create the instructions for making an object of a class. Arrays of Records Being able to create and populate a single record is not extremely useful. However, using an array of records allows for far greater control of the data structure, making searching and sorting much easier. Predefined Functions Below is a comprehensive list of all the main predefined functions in Python that you need to know for Higher Computing Science: Chr () Float () Input () Int () Len () Ord () Print () Range () Round () Str () At Higher level you will need to be able to explain and use functions for substrings, ascii conversions, casting between floats/integers and modulus. Casting between floats and integers Casting refers to the process of converting a piece of data from one data type to another. We can convert the string ‘99’ to the integer ‘99’ using the int () in Python for instance. The int () function can also be used in Python to cast from a floating-point number to an integer. When this is done the floating-point number will effectively be rounded down to the nearest integer. 1. Pi = 3.14159 2. Picast = int(pi) 3. Print(picast) 4. E = 2.71828 5. Ecast = int(e) 6. Print(ecast) Another method available to a programmer when casting between floats and integers is to use FLOOR () and CEILING () functions. In python these are available as part of the math library. A CEILING () function will round a float up to the next nearest integer and a FLOOR (0) function will round a float down to the closest earlier integer. 1. Import math 2. Pi = 3.14159 3. Pidown = math.floor(pi) 4. Print(pidown) 5. Piup = math.celi(pi) 6. Print(piup) You can check a type as a part of a condition, e.g.: if type(number) == int: Integer division Integer division refers to the rounding down of a float to the nearest lower integer. In python integer division is achieved with the double forward slash: //. 1. Print (15/7) 2. Print (15//7) 3. Print (5/2) 4. Print (5//2) 5. Print (13/7) 6. Print (13//7) Modulus The modulus function is a function (or operator) which returns the reminder when a number is divided by another. If a = 13 and b = 5 then a modulus b will return 3 since the remainder when 13 is divided by 5 is 3. In python the modulus operator is the % 1. Print (10%2) 2. Print (10%3) 3. Print (10%4) 4. Print (10%5) NOTE: It is possible to determine whether a number is even or odd using the modulus operator! Consider this small block of code: 1. For n in range (1,11): 2. If n%2 == 0: 3. Print (n, “is even”) 4. Else: 5. Print (n, “is odd”) ASCII Conversions In python the two functions Ord () and chr () allow a programmer to convert from an ascii character’s character to its numeric value or vice versa. 1. Character = “B” 2. Print (Ord(character)) 3. Numeric = 66 4. Print (chr (numeric)) NOTE: The upper case letters of ascii begin at 65 and finish at 90. The lower case letters begin at 97 and finish at 122. This means that to map from an upper case letter to the corresponding lower case letter we would need to add 32. Functions for substrings A substring is a part of a larger string. We could say that ‘mile’ is a substring of ‘smiled’ or that ‘Bob’ is a substring from ‘builder, Bob’. Name = “Bob Herb Builder” middlename = name [4:8] print(middlename) The code should output the string “Herb” NOTE: In python the substring will NOT include the character at the second integer value – the slicing stops when it gets to the second index. File Handling Files provide a way of storing data over the long term. In this course, your programs could be required to read from and write to either text or CSV (comma separated value) files. A file is a collection of information which is stored on backing storage. We could use applications or programs to create files. So, we would use a program like Microsoft Word to create a document file. We could use Notepad to create a text file. Files tend to be stored in a particular way, or format: the bit pattern obeys a certain, very specific, set of rules. The format of a file very often indicated by the extension at the end of the name. So a file called countries.txt is a text file. The following functions are fundamental for files to work on computer systems. We need to be able to: − Open files that already exist − Create files that don’t already exist − Read data out of a file − Write new data to files − Close an active file Typical text file extensions We will normally work with one of the following file types: File Type Example CSV (Comma Separated Values) Betty, Canada, 45 A file which has each individual data item Ailesh, Russia, 33 stored between commas and then new George, Algeria, 29 lines will generally separate the ‘record’. Kathy, Japan, 34 The program most commonly associated NOTE: with a CSV file is a spreadsheet. From our POV this will in fact be stored as “Betty, Canada, 45/nSailesh, Russia, 33/nGeorge...” where /n represents a non- printable character to show where the end of a line is TXT Betty Canada 45 A basic text file. The data in the file might Sailesh Russia 33 be separated using commas, tabs or NOTE: spaces. Once again,new lines(“/n”) will usually end lines. You can open a text file to preview its contents, so that you kno what you’re dealing with.

Use Quizgecko on...
Browser
Browser