SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
Lecture 02
Number Systems
Overview of Programming
CSE115: Computing Concepts
Complement
• Complement is the negative equivalent of a number.
• If we have a number N then complement of N will give us
another number which is equivalent to –N
• So if complement of N is M, then we can say M = -N
• So complement of M = -M = -(-N) = N
• So complement of complement gives the original number
Types of Complement
• For a number of base r, two types of complements can be found
 1. r’s complement
 2. (r-1)’s complement
• Definition:
 If N is a number of base r having n digits then
o r’s complement of N = rn – N and
o (r-1)’s complement of N = rn-N-1
Example
• Suppose N = (3675)10
• So we can find two complements of this number. The 10’s
complement and the 9’s complement. Here n = 4
• 10’s complement of (3675) = 104 - 3675
= 6325
• 9’s complement of (3675) = 104 - 3675 -1
= 6324
Short cut way to find (r-1)’s complement
• In the previous example we see that 9’s complement of 3675 is
6324. We can get the result by subtracting each digit from 9.
• Similarly for other base, the (r-1)’s complement can be found by
subtracting each digit from r-1 (the highest digit in that system).
• For binary 1’s complement is even more easy. Just change 1 to 0
and 0 to 1. (Because 1-1=0 and 1-0=1)
Example
• Find the (r-1)’s complement in short cut method.
 (620143)8 Ans: 157634
 (A4D7E)16 Ans: 5B281
 (110100101)2 Ans: 001011010
Short cut way to find r’s complement
• From the definition we can say,
 r’s complement of (N) = (r-1)’s complement +1
• So, we can first find the (r-1)’s complement in short cut way
then add 1 to get the r’s complement.
• Example: r’s complement of (620143)8 =157634 + 1
= 157635
This method is a two step process. But we can find it in a one
step process also.
Short cut way to find r’s complement
• One step process:
 Start from rightmost digit to left.
 Initial zeros will remain unchanged
 Rightmost non-zero digit will be subtracted from r
 Rest of the digits will be subtracted from r-1
• Example:
 Find the 10’s complement of (529400)10
 Rightmost 2 zeros will not change, 4 will be subtracted
from 10 and rest of the digits 529 will be subtracted
from 9
 So the result is 470600
Example
• Find the r’s complement in short cut method.
• (8210)10 Ans: 1790
• (61352)10 Ans: 38648
• (6201430)8 Ans: 1576350
• (A4D7E0)16 Ans: 5B2820
Example for binary
• For binary: start from rightmost bit
• Up to first 1 – no change.
• For rest of the bits toggle (Change 1 to 0 and 0 to 1)
 (11010010100)2 Ans: 00101101100
 (01101001011)2 Ans: 10010110101
 (10000000)2 Ans: 10000000
Use of Complement
• Complement is used to perform subtraction using addition
• Mathematically A-B = A + (-B)
• So we can get the result of A-B by adding complement of B with A.
• So A-B = A + Complement of (B)
Addition and Subtraction
◦ Two's complement addition follows the same rules as binary addition.
◦ Two's complement subtraction is the binary addition of the minuend to the 2's
complement of the subtrahend (adding a negative number is the same as
subtracting a positive one).
5 + (-3) = 2 0000 0101 = +5
+ 1111 1101 = -3
0000 0010 = +2
7 - 12 = (-5) 0000 0111 = +7
+ 1111 0100 = -12
1111 1011 = -5
Section 2
Introduction to programming
Computer Hardware Components
Components of a PC
Input / Output Devices
•Input Devices
• Accepts information from the user and
transforms it to digital codes that the computer
can process
• Example: keyboard, mouse, scanner
•Output Devices
• An interface by which the computer conveys
the output to the user
• Example: monitor, printer
Main Memory
• A semiconductor device which stores the information
necessary for a program to run.
• 2 types
• ROM (Read Only Memory)
• Contains information that is necessary for the computer to boot up
• The information stays there permanently even when the computer is
turned off.
• RAM (Random Access Memory)
• Contains instruction or data needed for a program to run
• Gets erased when the computer is turned off.
Central Processing Unit (CPU)
• Does most of the work in executing a program
• The CPU inside a PC is usually the microprocessor
• 3 main parts:
• Control Unit
• Fetch instructions from main memory and put them in the instruction register
• ALU (Arithmetic Logic Unit)
• Execute arithmetic operations
• Registers
• Temporarily store instructions or data fetched from memory
Storage Devices
• A magnetic device used to store a large amount of
information.
• Store the software components or data needed
for the computer to execute its tasks.
• Can be “read only” or “writable”.
• Example: Hard drive, CD ROM, floppy disks
Network Devices
• Connect a computer to the other computers.
• Enable the users to access data or execute
programs remotely.
• Example: modem, Ethernet card
Natural language
• Our everyday-language; spoken and written
• Not 100% needed to understand:
• “Do you want to buy this computer ?” remains comprehensible
• Depends on circumstances; the context:
• “Do you like one ?” doesn't make sense on its own. It needs a situation
around it:
• someone holding a bouquet of flowers: you might take one
• someone pointing to an expensive car: your opinion is asked
• someone 'offers' you an oily cloth to sneeze: you don't take it
Semantics and Syntax
• Semantics – the meaning of the language within a given
context
• Syntax - Syntax are the rules to join words
together in forming a correct expression or phrase.
• In natural languages it is often possible to assemble a
sentence in more than one correct ways.
What is Programming?
• Programming is instructing a computer to do something for you with the help of
a programming language
• The two roles of a programming language:
• Technical: It instructs the computer to perform tasks.
• Conceptual: It is a framework within which we organize our ideas about
things and processes.
• In programming, we deal with two kind of things:
• Data - representing 'objects' we want to manipulate
• Procedures -'descriptions' or 'rules' that define how to manipulate data.
Programming Language
• A programming language contains instructions for the
computer to perform a specific action or a specific task:
• 'Calculate the sum of the numbers from 1 to 10‘
• 'Print “I like programming”‘
• 'Output the current time'
Programming Language
• Can be classified into as a special-purpose and general-purpose
programming languages.
• Special-purpose : is design for a particular type of application
• Structured Query Language (SQL)
• General-purpose : can be used to obtain solutions for many types
of problems
• Machine Languages
• Assembly Languages
• High-Level Languages
Machine Language
• The only language that the processor actually 'understands‘
• Consists of binary codes: 0 and 1
• Example: 00010101
11010001
01001100
• Each of the lines above corresponds to a specific task to be done by
the processor.
• Programming in machine code is difficult and slow since it is
difficult to memorize all the instructions.
• Mistakes can happen very easily.
• Processor and Architecture dependent
Assembly Language
• Enables machine code to be represented in words and numbers.
• Example of a program in assembler language:
LOAD A, 9999
LOAD B, 8282
SUB B
MOV C, A
LOAD C, #0002
DIV A, C
STORE A, 7002
• Easier to understand and memorize (called Mnemonics), compared
to machine code but still quite difficult to use.
• Processor and Architecture dependent
High-Level Language
• Use more English words. They try to resemble English sentences.
Therefore, it is easier to program in these languages.
• The programming structure is problem oriented - does not need to
know how the computer actually executes the instructions.
• Processor independent - the same code can be run on different
processors.
• Examples: Basic, Fortran, Pascal, Cobol, C, C++, Java
• A high level language needs to be analyzed by the compiler and
then compiled into machine code so that it can be executed by the
processor.
C Programming Language
Why 'C' ?
• Because based on 'B'; developed at Bell Laboratories
• Developed by Dennis Ritchie at Bell Laboratories in the
1960s
• In cooperation with Ken Thomson it was used for Unix
systems
• The C Language was only vaguely defined, not
standardized, so that almost everyone had his own
perception of it, to such an extend that an urgent need
for a standard code was creeping up
C Programming Language
• In 1983, the American National Standards Institute (ANSI)
set up X3J11, a Technical Committee to draft a proposal
for the ANSI standard, which was approved in 1989 and
referred to as the ANSI/ISO 9899 : 1990 or simply the
ANSI C, which is now the global standard for C.
• This standard was updated in 1999; but there is no
compiler yet
A Simple Program in C
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!n");
return 0;
}
A Simple Program in C
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!n");
return 0;
}
standard Library, input-output, header-file
A Simple Program in C
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!n");
return 0;
}
Beginning of program
A Simple Program in C
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!n");
return 0;
}
End of Segment
Start of Segment
A Simple Program in C
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!n");
return 0;
}
Function for printing text
End of statement
Insert a new line
Output
Hello world!

Contenu connexe

Tendances

(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programmingNico Ludwig
 
C++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer CentreC++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer Centrejatin batra
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSAami Kakakhel
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overviewTAlha MAlik
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringSri Harsha Pamu
 
Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1Ali Aminian
 
C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokeC programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokePranoti Doke
 
Introduction To Algorithm [2]
Introduction To Algorithm [2]Introduction To Algorithm [2]
Introduction To Algorithm [2]ecko_disasterz
 
Program execution, straight line sequence and branching
Program execution, straight line sequence and branchingProgram execution, straight line sequence and branching
Program execution, straight line sequence and branchingJyotiprakashMishra18
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming LanguageSteve Johnson
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusDhivyaSubramaniyam
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesProgramming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesSreedhar Chowdam
 

Tendances (20)

C programming
C programmingC programming
C programming
 
C++ Tokens
C++ TokensC++ Tokens
C++ Tokens
 
C language programming
C language programmingC language programming
C language programming
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
 
C++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer CentreC++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer Centre
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICS
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
c++
 c++  c++
c++
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational Engineering
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
C++ for beginners
C++ for beginnersC++ for beginners
C++ for beginners
 
Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1
 
C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokeC programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti Doke
 
Introduction To Algorithm [2]
Introduction To Algorithm [2]Introduction To Algorithm [2]
Introduction To Algorithm [2]
 
Program execution, straight line sequence and branching
Program execution, straight line sequence and branchingProgram execution, straight line sequence and branching
Program execution, straight line sequence and branching
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabus
 
Vhdl introduction
Vhdl introductionVhdl introduction
Vhdl introduction
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesProgramming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture Notes
 

Similaire à Cse115 lecture02overviewofprogramming

Chapter 1 Introduction to computer components
Chapter 1 Introduction to computer componentsChapter 1 Introduction to computer components
Chapter 1 Introduction to computer componentsBoonsaaMulataa
 
Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Mohamed El Desouki
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programmingSangheethaa Sukumaran
 
l1-introduction_to_computers_and_c_programming.pptx
l1-introduction_to_computers_and_c_programming.pptxl1-introduction_to_computers_and_c_programming.pptx
l1-introduction_to_computers_and_c_programming.pptxssuser6f38e5
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Amr Alaa El Deen
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptxchouguleamruta24
 
C++ programming languages lectures
C++ programming languages lectures C++ programming languages lectures
C++ programming languages lectures jabirMemon
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfMMRF2
 
Unit-1_Digital Computers, number systemCOA[1].pptx
Unit-1_Digital Computers, number systemCOA[1].pptxUnit-1_Digital Computers, number systemCOA[1].pptx
Unit-1_Digital Computers, number systemCOA[1].pptxVanshJain322212
 

Similaire à Cse115 lecture02overviewofprogramming (20)

Chapter 1 Introduction to computer components
Chapter 1 Introduction to computer componentsChapter 1 Introduction to computer components
Chapter 1 Introduction to computer components
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
l1-introduction_to_computers_and_c_programming.pptx
l1-introduction_to_computers_and_c_programming.pptxl1-introduction_to_computers_and_c_programming.pptx
l1-introduction_to_computers_and_c_programming.pptx
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
lec 1.pptx
lec 1.pptxlec 1.pptx
lec 1.pptx
 
01CHAP_1.PPT
01CHAP_1.PPT01CHAP_1.PPT
01CHAP_1.PPT
 
Mcs lec2
Mcs lec2Mcs lec2
Mcs lec2
 
PPS Unit-1.pdf
PPS Unit-1.pdfPPS Unit-1.pdf
PPS Unit-1.pdf
 
PSPC--UNIT-1.pdf
PSPC--UNIT-1.pdfPSPC--UNIT-1.pdf
PSPC--UNIT-1.pdf
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
 
Lecture1
Lecture1Lecture1
Lecture1
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptx
 
C++ programming languages lectures
C++ programming languages lectures C++ programming languages lectures
C++ programming languages lectures
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
Unit-1_Digital Computers, number systemCOA[1].pptx
Unit-1_Digital Computers, number systemCOA[1].pptxUnit-1_Digital Computers, number systemCOA[1].pptx
Unit-1_Digital Computers, number systemCOA[1].pptx
 

Dernier

Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfsmsksolar
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersMairaAshraf6
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 

Dernier (20)

Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 

Cse115 lecture02overviewofprogramming

  • 1. Lecture 02 Number Systems Overview of Programming CSE115: Computing Concepts
  • 2. Complement • Complement is the negative equivalent of a number. • If we have a number N then complement of N will give us another number which is equivalent to –N • So if complement of N is M, then we can say M = -N • So complement of M = -M = -(-N) = N • So complement of complement gives the original number
  • 3. Types of Complement • For a number of base r, two types of complements can be found  1. r’s complement  2. (r-1)’s complement • Definition:  If N is a number of base r having n digits then o r’s complement of N = rn – N and o (r-1)’s complement of N = rn-N-1
  • 4. Example • Suppose N = (3675)10 • So we can find two complements of this number. The 10’s complement and the 9’s complement. Here n = 4 • 10’s complement of (3675) = 104 - 3675 = 6325 • 9’s complement of (3675) = 104 - 3675 -1 = 6324
  • 5. Short cut way to find (r-1)’s complement • In the previous example we see that 9’s complement of 3675 is 6324. We can get the result by subtracting each digit from 9. • Similarly for other base, the (r-1)’s complement can be found by subtracting each digit from r-1 (the highest digit in that system). • For binary 1’s complement is even more easy. Just change 1 to 0 and 0 to 1. (Because 1-1=0 and 1-0=1)
  • 6. Example • Find the (r-1)’s complement in short cut method.  (620143)8 Ans: 157634  (A4D7E)16 Ans: 5B281  (110100101)2 Ans: 001011010
  • 7. Short cut way to find r’s complement • From the definition we can say,  r’s complement of (N) = (r-1)’s complement +1 • So, we can first find the (r-1)’s complement in short cut way then add 1 to get the r’s complement. • Example: r’s complement of (620143)8 =157634 + 1 = 157635 This method is a two step process. But we can find it in a one step process also.
  • 8. Short cut way to find r’s complement • One step process:  Start from rightmost digit to left.  Initial zeros will remain unchanged  Rightmost non-zero digit will be subtracted from r  Rest of the digits will be subtracted from r-1 • Example:  Find the 10’s complement of (529400)10  Rightmost 2 zeros will not change, 4 will be subtracted from 10 and rest of the digits 529 will be subtracted from 9  So the result is 470600
  • 9. Example • Find the r’s complement in short cut method. • (8210)10 Ans: 1790 • (61352)10 Ans: 38648 • (6201430)8 Ans: 1576350 • (A4D7E0)16 Ans: 5B2820
  • 10. Example for binary • For binary: start from rightmost bit • Up to first 1 – no change. • For rest of the bits toggle (Change 1 to 0 and 0 to 1)  (11010010100)2 Ans: 00101101100  (01101001011)2 Ans: 10010110101  (10000000)2 Ans: 10000000
  • 11. Use of Complement • Complement is used to perform subtraction using addition • Mathematically A-B = A + (-B) • So we can get the result of A-B by adding complement of B with A. • So A-B = A + Complement of (B)
  • 12. Addition and Subtraction ◦ Two's complement addition follows the same rules as binary addition. ◦ Two's complement subtraction is the binary addition of the minuend to the 2's complement of the subtrahend (adding a negative number is the same as subtracting a positive one). 5 + (-3) = 2 0000 0101 = +5 + 1111 1101 = -3 0000 0010 = +2 7 - 12 = (-5) 0000 0111 = +7 + 1111 0100 = -12 1111 1011 = -5
  • 15. Input / Output Devices •Input Devices • Accepts information from the user and transforms it to digital codes that the computer can process • Example: keyboard, mouse, scanner •Output Devices • An interface by which the computer conveys the output to the user • Example: monitor, printer
  • 16. Main Memory • A semiconductor device which stores the information necessary for a program to run. • 2 types • ROM (Read Only Memory) • Contains information that is necessary for the computer to boot up • The information stays there permanently even when the computer is turned off. • RAM (Random Access Memory) • Contains instruction or data needed for a program to run • Gets erased when the computer is turned off.
  • 17. Central Processing Unit (CPU) • Does most of the work in executing a program • The CPU inside a PC is usually the microprocessor • 3 main parts: • Control Unit • Fetch instructions from main memory and put them in the instruction register • ALU (Arithmetic Logic Unit) • Execute arithmetic operations • Registers • Temporarily store instructions or data fetched from memory
  • 18. Storage Devices • A magnetic device used to store a large amount of information. • Store the software components or data needed for the computer to execute its tasks. • Can be “read only” or “writable”. • Example: Hard drive, CD ROM, floppy disks
  • 19. Network Devices • Connect a computer to the other computers. • Enable the users to access data or execute programs remotely. • Example: modem, Ethernet card
  • 20. Natural language • Our everyday-language; spoken and written • Not 100% needed to understand: • “Do you want to buy this computer ?” remains comprehensible • Depends on circumstances; the context: • “Do you like one ?” doesn't make sense on its own. It needs a situation around it: • someone holding a bouquet of flowers: you might take one • someone pointing to an expensive car: your opinion is asked • someone 'offers' you an oily cloth to sneeze: you don't take it
  • 21. Semantics and Syntax • Semantics – the meaning of the language within a given context • Syntax - Syntax are the rules to join words together in forming a correct expression or phrase. • In natural languages it is often possible to assemble a sentence in more than one correct ways.
  • 22. What is Programming? • Programming is instructing a computer to do something for you with the help of a programming language • The two roles of a programming language: • Technical: It instructs the computer to perform tasks. • Conceptual: It is a framework within which we organize our ideas about things and processes. • In programming, we deal with two kind of things: • Data - representing 'objects' we want to manipulate • Procedures -'descriptions' or 'rules' that define how to manipulate data.
  • 23. Programming Language • A programming language contains instructions for the computer to perform a specific action or a specific task: • 'Calculate the sum of the numbers from 1 to 10‘ • 'Print “I like programming”‘ • 'Output the current time'
  • 24. Programming Language • Can be classified into as a special-purpose and general-purpose programming languages. • Special-purpose : is design for a particular type of application • Structured Query Language (SQL) • General-purpose : can be used to obtain solutions for many types of problems • Machine Languages • Assembly Languages • High-Level Languages
  • 25. Machine Language • The only language that the processor actually 'understands‘ • Consists of binary codes: 0 and 1 • Example: 00010101 11010001 01001100 • Each of the lines above corresponds to a specific task to be done by the processor. • Programming in machine code is difficult and slow since it is difficult to memorize all the instructions. • Mistakes can happen very easily. • Processor and Architecture dependent
  • 26. Assembly Language • Enables machine code to be represented in words and numbers. • Example of a program in assembler language: LOAD A, 9999 LOAD B, 8282 SUB B MOV C, A LOAD C, #0002 DIV A, C STORE A, 7002 • Easier to understand and memorize (called Mnemonics), compared to machine code but still quite difficult to use. • Processor and Architecture dependent
  • 27. High-Level Language • Use more English words. They try to resemble English sentences. Therefore, it is easier to program in these languages. • The programming structure is problem oriented - does not need to know how the computer actually executes the instructions. • Processor independent - the same code can be run on different processors. • Examples: Basic, Fortran, Pascal, Cobol, C, C++, Java • A high level language needs to be analyzed by the compiler and then compiled into machine code so that it can be executed by the processor.
  • 28.
  • 29. C Programming Language Why 'C' ? • Because based on 'B'; developed at Bell Laboratories • Developed by Dennis Ritchie at Bell Laboratories in the 1960s • In cooperation with Ken Thomson it was used for Unix systems • The C Language was only vaguely defined, not standardized, so that almost everyone had his own perception of it, to such an extend that an urgent need for a standard code was creeping up
  • 30. C Programming Language • In 1983, the American National Standards Institute (ANSI) set up X3J11, a Technical Committee to draft a proposal for the ANSI standard, which was approved in 1989 and referred to as the ANSI/ISO 9899 : 1990 or simply the ANSI C, which is now the global standard for C. • This standard was updated in 1999; but there is no compiler yet
  • 31. A Simple Program in C #include <stdio.h> #include <stdlib.h> int main() { printf("Hello world!n"); return 0; }
  • 32. A Simple Program in C #include <stdio.h> #include <stdlib.h> int main() { printf("Hello world!n"); return 0; } standard Library, input-output, header-file
  • 33. A Simple Program in C #include <stdio.h> #include <stdlib.h> int main() { printf("Hello world!n"); return 0; } Beginning of program
  • 34. A Simple Program in C #include <stdio.h> #include <stdlib.h> int main() { printf("Hello world!n"); return 0; } End of Segment Start of Segment
  • 35. A Simple Program in C #include <stdio.h> #include <stdlib.h> int main() { printf("Hello world!n"); return 0; } Function for printing text End of statement Insert a new line