Computer Programming (CS101) Lecture-02 Asst Prof. Rizwan Khan Department of Computer & Engineering rizwan.khan@abesit.in
Introduction to programming
What is a program? How to cook? The algorithm Are you a programmer? Computer Programming 7/22/2019
Pseudocode This is the pseudocode for a game of Monopoly Computer Programming 7/22/2019
Flowcharts Computer Programming 7/22/2019
Flowcharts details Computer Programming 7/22/2019
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
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
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
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
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
Number Systems
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
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
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
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
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
Conversion Among Bases The possibilities: Decimal Octal Binary Hexadecimal Computer Programming 7/22/2019
2510 = 110012 = 318 = 1916 Quick Example Base Computer Programming 7/22/2019
Decimal to Decimal (just for fun) Octal Binary Hexadecimal Next slide… Computer Programming 7/22/2019
Weight 12510 => 5 x 100 = 5 2 x 101 = 20 1 x 102 = 100 125 Base Computer Programming 7/22/2019
Binary to Decimal Decimal Octal Binary Hexadecimal Computer Programming 7/22/2019
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
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 7/22/2019
Octal to Decimal Decimal Octal Binary Hexadecimal Computer Programming 7/22/2019
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
Example 7248 => 4 x 80 = 4 2 x 81 = 16 7 x 82 = 448 46810 Computer Programming 7/22/2019
Hexadecimal to Decimal Octal Binary Hexadecimal Computer Programming 7/22/2019
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
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 7/22/2019
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 1110101 555 1FD 100101 703 11CE 101010 222 1AF Computer Programming 7/22/2019