Documente Academic
Documente Profesional
Documente Cultură
- 41 -
Computer notes
Published By: Muhammad Jalil Instructor Al-Mustafa Public School and College Gilgit.
- 42 -
- 43 -
Data is the plural of word datum, which means raw facts. The collection of facts and figures is called data e.g. name, address, date and cost etc. 2. Information: Information is data which has been transformed into meaningful and useful results is called information e.g. report card, pay slip and project reports etc.
NUMBER SYSTEM
Q1. What is number system? Discuss different number system. Human during the evolution of civilizations has invented many numbers system. All number system used to suit different working condition and requirements. The total number of digits used in a number system is called its base or radix. Some number systems are discussed below. 1. Decimal number system: This number system we used in our daily routine work. It consists of ten digits that are from 0 to 9. Therefore base of this system is 10. 2. Binary number system: Computer can process only binary numbers. This number system consists of two digits, the 0 and 1. Therefore base of this system is 2. 3. Octal number system:
Prepared by MUHAMMAD JALIL AL-MUSTAFA PUBLIC SCHOOL AND COLLEGE GILGIT
- 44 -
This system is a short hand version of binary numbers. It consists of eight digits that are from 0 to 7. Therefore base of this system is 8. 4. Hexadecimal number system: This is also short hand version of binary numbers. It comprises of sixteen numbers, the 0 and 15. Therefore the base of this system is 16. Here the symbols A,, F in hex stands respectively for 10,,15 in decimal. Q2. Convert the following decimal number into other number system. Conversion of decimal into any other number is very simple and easy. Just divide the decimal number by the base in which conversion required, remainder save and continuing the same procedure till the decimal number become less then the base. After that stored remainder write from bottom to top as result. 1. Convert (23)10 and (20)10 into binary number system. 2 2 2 2 23 11 1 5 1 2 1 1 0 (10111) 2 2. 2 2 2 2 20 10 0 5 0 2 1 1 0 (10100) 2
Convert (8610) 10 and (9001) 10 into octal number system. 8 8 8 8 8 86610 1076 134 16 2 2 4 6 0 8 8 8 8 8 9001 1125 140 17 2 1 5 4 1
(20642)8 (21451) 8 Q3. Convert the following Binary number into other number system. Conversion of any other number system to decimal number system is also a easy task. Simply each digit multiplied by its base and then add it. The base must containing appropriate power. The procedure of converting into decimal number is shown in the following example. 1. Convert the binary number into decimal number system. (11101)2 = 124 + 123 + 122 + 0 21 + 1 20 = 116 +18 +14 + 02 +11 = 16 + 8 + 4 + 0 + 1 = (29)10 Convert the octal number into decimal number system. (357)5 = 3 82 + 5 81 + 7 80 = 3 64 + 5 8 + 7 1 = 192 + 40 + 7 = (239)10
2.
- 45 -
Chapter 6
Boolean Algebra
Boolean Algebra
The Boolean algebra was developed by the English mathematician George Boole. It deals with statements in mathematical logic, and puts them in the form of algebraic equations. The modern American mathematician Cluade Shannon fourth developed the Boolean algebra, in order to apply to computer. Boolean algebra is used in designing of logic circuits inside the computer. These circuits perform different types of logical operations. ELEMENTS OF BOOLEAN ALGEBRA: In Boolean algebra an expression can be formed using binary variables, constants, symbols of logic operations and parentheses. BOOLEAN VARIABLES:The variables used in Boolean algebra can be represented by letters of the alphabetic having values;1 and 0. BOOLEAN CONSTANTS:In Boolean algebra a set of constants has only two elements 0 or 1.. Thus Boolean constant is either 0 if not 1. or is 1 if not 0. BOOLEAN OPERATORS:AND OPERATION: In Boolean algebra AND operator is represented by a dot or by the absence of any symbol between two variables and is used for logical multiplication. For example: A.B =X or AB=X OR OPERATION: Or operation is represented by a plus sign between two variables. In Boolean algebra OR is used for logical addition. For Example A+ B=X NOT OPERATORS: NOT operation is a unary operation which is the negation of the value of a variable on which NOT operates. SIMPLIFICATION OF BOOLEAN FUNCTION The basic approach is to proceed from a statement of the function to a truth table and then to a Boolean expression of the function. This Boolean expression is then simplified as much as possible using Boolean rules. TROUTH TABLE: A truth table is a table that shows the result of a Boolean Expression for all the possible combinations of the values given to the variable. KARNAUGH MAPS Kamaugh map provides a systematic method for simplifying Boolean expressions and if properly used will produce the simplest SOP or POS expression possible. A karnaugh is similar to a truth table because it presents all of the possible values of input variables and the result ion output for each value. Karnaugh maps can be used for expressions with two, three, four, and five variables.
- 46 -
3. Rectangle (Process box): A process box is used to indicate any type of arithmetic calculation and data movement instructions. Mathematical formulas are use to in this box.
4. Diamond (Decision box): The decision symbol is used to indicate a decision or action the computer is to be taken. A decision box contains a question with Yes or No answer.
- 47 -
5. Connector (Circle): If the program is long and a many places flow lines cries crossing that cause confusion, so that flow chart connected by the connector. On page connector connect the flow at the same page. 6. Flow line (Arrow): The flow chart symbols are connected together by means of flow lines. Flow lines indicate the flow of operation.
- 48 -
BASIC OPERATORS:
Operators are lexical entity that indicates the action to be performed on operands. Operators perform mathematical or logical operation on value. There are three types of operators. 1. Arithmetic operators 2. Relational operators 3. Logical operators 1. ARITHEMATIC OPERATORS: The arithmetic operators perform the usual operation of arithmetic such as addition and subtraction. In order of precedence, they are: OPERATORS + * / ^ OPERATION Addition Subtraction Multiplication Division Exponentiation/Power
2. RELATIONAL OPERATORS: The relational operators compare two values. The values may be either numeric or both strings. The result of comparison is either true or false. OPERATORS = <> < > <= or =< >= or => RELATION TESTED Equality Inequality Less than Greater than Less than or equal to Greater than or equal to
3. LOGICAL OPERATORS:
Prepared by MUHAMMAD JALIL AL-MUSTAFA PUBLIC SCHOOL AND COLLEGE GILGIT
- 49 -
The logical operators perform logical calculation. Logical operators combination of true or false values and return are true or false result. OPERATORS NOT AND OR OPERATION Logical complement Conjunction Disjunction
- 50 -
Command: 1. The instructions which a computer process immediately and output a result at the time of enter key pressing are called command. 2. Commands are written without line number. Statement: 1. The instructions which a computer process but the output provide at the time of program execution are called statements. 2. The statements are written with line number. This line number must be written in the start of statement.
ERRORS
1. Syntax error and Logical error 2. Bug and Debugging SYNTAX ERROR: Syntax error is computer grammatical mistake, such as an unmatched parenthesis, incorrect punctuation or used incorrect spelling of command and statement. This type of errors is very easy to find and correct. LOGICAL ERROR: Logical errors are much more difficult to detect, since the output resulting from a logically incorrect program may appear to be error free. BUG: An error malfunctions in computer program and computer system is called bug. DEBUGGING: To locate and correct any error in a computer program and computer system is called debugging.
- 51 -
AUTO 100,5
LIST 100
4. DELETE: (command) Syntax: DELETE [starting line no.]-[ending line no.] Purpose: Erase the specified range of lines of the program from computer memory. Example: DELETE 40 or DELETE 50-200 5. EDIT: (command) Syntax: EIDT [line no.] Purpose: Display the specified line and change the line. Example: EIDT 50 6. LOAD: (command) Syntax: LOADfile name Purpose: Reads a program from a specified device and store it in memory. Example: LOADTEST or LOADTEST,R 7. SAVE: (command) Syntax: SAVEfile name Purpose: Save a program file in a disk. Example: SAVETEST or SAVEB:TEST 8. RUN: (command) Syntax: RUN Purpose: Execute of the program currently in memory. Example: RUN 9. NEW: (command) Syntax: NEW Purpose: Delete the program currently in memory and clear all variables. Example: NEW
Prepared by MUHAMMAD JALIL AL-MUSTAFA PUBLIC SCHOOL AND COLLEGE GILGIT
- 52 -
13. INPUT: (statement) Syntax: INPUT string[;/,]variable Purpose: To take the instruction from keyboard during the execution of program. Example: 50 INPUT enter name, N$ 14. PRINT: (statement) Syntax: PRINT string[variable] Purpose: To transmit the data and output on a screen. Example: 40 PRINT YOUR NAMEN$ 15. LET: (statement) Syntax: LET variable=expression Purpose: To assign the value of expression to a variable. Example: 20 LET A=4 or 30 LET N$=ALI 16. GOTO: (statement) Syntax: GOTO line no. Purpose: To branches unconditionally to the specified line number. Example: 100 GOTO 20 17. KEY: (statement) Syntax: KEY n,text, KEY LIST, KEY ON/OFF Purpose: To assign the function key, display the list of function keys and on/off the key. Example: KEY 2,FILES or KEY LIST or KEY ON or KEY OFF 18. FILES: (command) Syntax: FILES Purpose: Display all names of files/programs from specified disk. Example: FILES or FILESB: 19. END: (statement) Syntax: END Purpose: To terminate the program execution and return to command level. Example: 100 END 20. STOP: (statement)
Prepared by MUHAMMAD JALIL AL-MUSTAFA PUBLIC SCHOOL AND COLLEGE GILGIT
- 53 -
21. CONT: (command) Syntax: CONT Purpose: Resume execution of an interrupted operation. Using Stop and End statement. Example: CONT 22. KILL: (command) Syntax: KILL filename Purpose: Delete a file/program from a diskette. Example: KILL test.bas 23. NAME: (statement) Syntax: NAME old filename AS new filename Purpose: To change the old file name in new file name. Example: NAME test.bas AS Nasir.bas 24. SHELL: (statement) Syntax: SHELL Purpose: To temporary exit from Basic to Dos command prompt. Example: SHELL 25. LOCATE: (statement) Syntax: LOCATE [row,column] Purpose: Moves the cursor to the specified position. Example: 30 LOCATE 5,10 26. SWAP: (statement) Syntax: SWAP variable, variable Purpose: To interchange the value of two variables. Example: 50 SWAP A, B or 60 SWAP A$,B$ 27. IF-THEN-ELSE: (statement) Syntax: IF [expression] THEN [statement] ELSE [statement] Purpose: To make a decision on the result of an expression. Example: 60 IF a=10 THEN 70 ELSE 20 28. FOR-NEXT: (statement) Syntax: FOR variable=starting no. TO ending no. [STEP] : NEXT Purpose: To perform a repetitive loop for given number of time. Example: 20 FOR A=1 to 10 : 100 NEXT A 29. GOSUB-RETURN: (statement) Syntax: GOSUB [line no.] : RETURN Purpose: To branch a subroutine and return from a subroutine. Example: 30 GOSUB 40 : 70 RETURN 30. READ-DATA: (statement)
Prepared by MUHAMMAD JALIL AL-MUSTAFA PUBLIC SCHOOL AND COLLEGE GILGIT
- 54 -
35. ON-GOSUB: (statement) 36. ON-GOTO: (statement) Syntax: ON [variable] GOSUB [line no. list] ON [variable] GOTO [line no. list] Purpose: Branches one or more specified line nos. depending on the value of expression. Example: 20 ON choice GOSUB 30,40,50 or 20 ON choice GOTO 30,40,50 37. CHAIN: (statement/command) Syntax: CHAIN file name Purpose: To call a program into memory and execute the program. Example: CHAIN test 38. LLIST: (command) Syntax: LLIST [starting line no.]-[ending line no.] Purpose: Print all or part of the program on the paper. Example: LLIST or LLIST 50-150 or LLIST 100 or LLIST 10039. LPRINT: (statement) Syntax: LPRINT expression Purpose: To print data or output on a paper. Example: 40 LPRINT NAME : NASIR 40. MERGE: (command) Syntax: MERGE file name Purpose: To combine a program into the program currently in memory.
Prepared by MUHAMMAD JALIL AL-MUSTAFA PUBLIC SCHOOL AND COLLEGE GILGIT
- 55 -
(GRAPHIC STATEMENTS)
44. SCREEN: Syntax: SCREEN [mode] Purpose: To sets the specifications for the display screen. Example: 20 SCREEN 0,0,0 or 20 SCREEN 1 or 20 SCREEN 2 45. CIRCLE: Syntax: CIRCLE (x,y),radius Purpose: To draw a circle, arc and ellipse on the screen. Example: 40 CIRCLE (100,160), 80 46. LINE: Syntax: LINE (x1,y1)-(x2,y2),color,box Purpose: To draw a line or box on the screen. Example: 30 LINE (10,50)-(30,40),2 47. DRAW: Syntax: DRAW string expression Purpose: To draws an object as specified by a string expression. Example: 20 DRAW f60 l120 e60 Dn=Move down Fn=Move diagonally down right Un=Move up Gn=Move diagonally down left Ln=Move left Hn=Move diagonally up left Rn=Move right En=Move diagonally up right Bn=Mover but no plot draw Nn=Move but return to previous position n=Number 48. PSET: Syntax: PSET (x,y),color Purpose: To set the pixel position on the screen. Example: 20 PSET (50,80),2 49. PAINT: Syntax: PAINT (x,y),[color,border,background] Purpose: To fill a diagram or area with a color and pattern. Example: 20 PAINT (100,160),2
(FUNCTIONS)
Prepared by MUHAMMAD JALIL AL-MUSTAFA PUBLIC SCHOOL AND COLLEGE GILGIT
- 56 -
- 57 -
- 58 -
3. IF-THEN:
Prepared by MUHAMMAD JALIL AL-MUSTAFA PUBLIC SCHOOL AND COLLEGE GILGIT
- 59 -
This statement is used to carry out a conditional branching operation. It transfers control to a specific portion of a program depending on the condition. If the condition is true then the control will be transferred to the first executable statement and if the condition is false the control will be transferred to the next executable statement.
FOR-NEXT loop
The FOR-NEXT statement specifies how many times the loop will be executed. This statement included in the FOR-NEXT statement and numeric variable called the running variable, whose value changes each time the loop is executed. The variables are specifying initial and final values. This loop always begins with a FORTO statement; it always ends with a NEXT statement. The complete loop included between the FOR-TO and the NEXT statement.
- 60 -
DIM statement
An array variable is allowed to range from 0 to 10. Whenever we want to store more than 10 values in an array in the memory, we accomplished by means of the DIM (DIMENSION) statement. For this purpose, we identify the total number of locations to be reserved in the computers memory. The DIM statement consists of a statement number, followed by the keyword DIM. The DIM statement allows a user to determine maximum array sizes easily and quickly.
DEF statement
Some time the programmer will want to write his own functions, to be used along with the library functions. For this purpose the DEF FN statement is used to define and name a function subprogram. In the DEF FN statement, arguments are used only to define the function; they do not affect program variable that has the same name. Both numeric and string function can be define with the DEF statement.
END
Prepared by MUHAMMAD JALIL AL-MUSTAFA PUBLIC SCHOOL AND COLLEGE GILGIT