Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Programming (CS101) Lecture-02

Similar presentations


Presentation on theme: "Computer Programming (CS101) Lecture-02"— Presentation transcript:

1 Computer Programming (CS101) Lecture-02
Asst Prof. Rizwan Khan Department of Computer & Engineering

2 Introduction to programming

3 What is a program? How to cook? The algorithm Are you a programmer?
Computer Programming 7/22/2019

4 Pseudocode This is the pseudocode for a game of Monopoly
Computer Programming 7/22/2019

5 Flowcharts Computer Programming 7/22/2019

6 Flowcharts details Computer Programming 7/22/2019

7 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 7/22/2019

8 Source code -> Object code
Compiler+linker Fortran, C, Pascal, C++… Interpreter Basic, Perl… Intermediate Java Compiler+linker Fast to execute, but slow to debug Interpreter Slow to execute, but fast to debug (no need to recompile) Intermediate Slow… Computer Programming 7/22/2019

9 Source code Instructions Data structures Statement, blocks Affectation
Operators Loops Tests Subroutines Comments Data structures Variable List Array Hash Pointers Objects Computer Programming 7/22/2019

10 Source code (2) Statement, blocks Affectation Operator Variable
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 7/22/2019

11 Source code (3) Pointers Loops Objects Tests Subroutines Comments
Reference to region in memory (address) Objects Combination of data and code 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… Computer Programming 7/22/2019

12 Number Systems

13 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-positional systems. Our main goal is to discuss the positional number systems, but we also give examples of non-positional systems. Computer Programming 7/22/2019

14 Common Number Systems System Base Symbols Used by humans?
Used in computers? Decimal 10 0, 1, … 9 Yes No Binary 2 0, 1 Octal 8 0, 1, … 7 Hexa- decimal 16 0, 1, … 9, A, B, … F Computer Programming 7/22/2019

15 Quantities/Counting (1 of 3)
Decimal Binary Octal Hexa- decimal 1 2 10 3 11 4 100 5 101 6 110 7 111 Computer Programming 7/22/2019

16 Quantities/Counting (2 of 3)
Decimal Binary Octal Hexa- decimal 8 1000 10 9 1001 11 1010 12 A 1011 13 B 1100 14 C 1101 15 D 1110 16 E 1111 17 F Computer Programming 7/22/2019

17 Quantities/Counting (3 of 3)
Decimal Binary Octal Hexa- decimal 16 10000 20 10 17 10001 21 11 18 10010 22 12 19 10011 23 13 10100 24 14 10101 25 15 10110 26 10111 27 Etc. Computer Programming 7/22/2019

18 Conversion Among Bases
The possibilities: Decimal Octal Binary Hexadecimal Computer Programming 7/22/2019

19 2510 = 110012 = 318 = 1916 Quick Example Base Computer Programming
7/22/2019

20 Decimal to Decimal (just for fun)
Octal Binary Hexadecimal Next slide… Computer Programming 7/22/2019

21 Weight 12510 => 5 x 100 = 5 2 x 101 = 20 1 x 102 = 100 125 Base
Computer Programming 7/22/2019

22 Binary to Decimal Decimal Octal Binary Hexadecimal
Computer Programming 7/22/2019

23 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 7/22/2019

24 Example Bit “0” => 1 x 20 = x 21 = x 22 = x 23 = x 24 = x 25 = 32 4310 Computer Programming 7/22/2019

25 Octal to Decimal Decimal Octal Binary Hexadecimal Computer Programming
7/22/2019

26 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 7/22/2019

27 Example 7248 => 4 x 80 = x 81 = x 82 = Computer Programming 7/22/2019

28 Hexadecimal to Decimal
Octal Binary Hexadecimal Computer Programming 7/22/2019

29 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 7/22/2019

30 Example ABC16 => C x 160 = 12 x 1 = B x 161 = 11 x 16 = A x 162 = 10 x 256 = 2560 274810 Computer Programming 7/22/2019

31 Assignment-02 1.List the differences between Compiler and interpreter.
2.List the differences between low level and high level languages. 3. Decimal Binary Octal Hexa- decimal 100010 403 2CB 555 1FD 100101 703 11CE 101010 222 1AF Computer Programming 7/22/2019


Download ppt "Computer Programming (CS101) Lecture-02"

Similar presentations


Ads by Google