310 likes | 353 Views
Computer Programming (CS101) Lecture-02. Asst Prof. Rizwan Khan Department of Computer & Engineering r izwan.khan@abesit.in. Introduction to programming. What is a program?. How to cook? The algorithm Are you a programmer?. Pseudocode. This is the pseudocode for a game of Monopoly.
E N D
Computer Programming(CS101)Lecture-02 Asst Prof.Rizwan Khan Department of Computer & Engineering rizwan.khan@abesit.in
What is a program? • How to cook? • The algorithm • Are you a programmer? Computer Programming
Pseudocode • This is the pseudocode for a game of Monopoly Computer Programming
Flowcharts Computer Programming
Flowcharts details Computer Programming
Languages • Low level (processor dependent) • Machine code, assembler • High level: structured, procedural • Fortran, C, Pascal… • High level: object oriented • C++, Java, C#, Perl, Objective-C… • Virtual machines • Java, C#… • Scripting • Perl, Python, JavaScript… Computer Programming
Source code -> Object code • Compiler+linker • Fortran, C, Pascal, C++… • Interpreter • Basic, Perl… • Intermediate • Java • Compiler+linker • Fast to execute, butslow to debug • Interpreter • Slow to execute, butfast to debug (no need to recompile) • Intermediate • Slow… Computer Programming
Source code • Instructions • Statement, blocks • Affectation • Operators • Loops • Tests • Subroutines • Comments • Data structures • Variable • List • Array • Hash • Pointers • Objects Computer Programming
Source code (2) • Statement, blocks • One or more instructions for the processor • Affectation • Change to a variable • Operator • affect one or more variable • + * - / AND OR NOT… • Variable • A region in memory that can be modified • Exists in different types • Scalar, char, numeric, boolean • List, array • Hash • Combination->data structure Computer Programming
Source code (3) • Loops • Allow the computer to repeat blocks • Tests • Decide what to do • Subroutines • Programs frequently called (functions) • Comments • The most important lines of the source code… • Pointers • Reference to region in memory (address) • Objects • Combination of data and code Computer Programming
2-1 INTRODUCTION A number system defines how a number can be represented using distinct symbols. A number can be represented differently in different systems. For example, the two numbers (2A)16 and (52)8 both refer to the same quantity, (42)10, but their representations are different. Several number systems have been used in the past and can be categorized into two groups: positional and non-positionalsystems. Our main goal is to discuss the positional number systems, but we also give examples of non-positional systems. Computer Programming
Common Number Systems Computer Programming
Quantities/Counting (1 of 3) Computer Programming
Quantities/Counting (2 of 3) Computer Programming
Quantities/Counting (3 of 3) Etc. Computer Programming
Conversion Among Bases • The possibilities: Decimal Octal Binary Hexadecimal Computer Programming
Quick Example 2510 = 110012 = 318 = 1916 Base Computer Programming
Decimal to Decimal (just for fun) Decimal Octal Binary Hexadecimal Next slide… Computer Programming
Weight 12510 => 5 x 100 = 5 2 x 101 = 20 1 x 102 = 100 125 Base Computer Programming
Binary to Decimal Decimal Octal Binary Hexadecimal Computer Programming
Binary to Decimal • Technique • Multiply each bit by 2n, where n is the “weight” of the bit • The weight is the position of the bit, starting from 0 on the right • Add the results Computer Programming
Example Bit “0” 1010112 => 1 x 20 = 1 1 x 21 = 2 0 x 22 = 0 1 x 23 = 8 0 x 24 = 0 1 x 25 = 32 4310 Computer Programming
Octal to Decimal Decimal Octal Binary Hexadecimal Computer Programming
Octal to Decimal • Technique • Multiply each bit by 8n, where n is the “weight” of the bit • The weight is the position of the bit, starting from 0 on the right • Add the results Computer Programming
Example 7248 => 4 x 80 = 4 2 x 81 = 16 7 x 82 = 448 46810 Computer Programming
Hexadecimal to Decimal Decimal Octal Binary Hexadecimal Computer Programming
Hexadecimal to Decimal • Technique • Multiply each bit by 16n, where n is the “weight” of the bit • The weight is the position of the bit, starting from 0 on the right • Add the results Computer Programming
Example ABC16 => C x 160 = 12 x 1 = 12 B x 161 = 11 x 16 = 176 A x 162 = 10 x 256 = 2560 274810 Computer Programming
Assignment-02 • 1.List the differences between Compiler and interpreter. • 2.List the differences between low level and high level languages. • 3. Computer Programming