0% found this document useful (0 votes)
15 views32 pages

Lec 1 - Numerical systems

The document provides an introduction to C++, an object-oriented programming language, covering its basic constructs, applications, and the importance of algorithms and flowcharts. It explains numeral systems including binary, octal, decimal, and hexadecimal, along with methods for converting between them. Additionally, it discusses binary shifting operations and includes practice problems with answers.

Uploaded by

shaikham2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views32 pages

Lec 1 - Numerical systems

The document provides an introduction to C++, an object-oriented programming language, covering its basic constructs, applications, and the importance of algorithms and flowcharts. It explains numeral systems including binary, octal, decimal, and hexadecimal, along with methods for converting between them. Additionally, it discusses binary shifting operations and includes practice problems with answers.

Uploaded by

shaikham2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Introduction to Programming C++

Introduction to Programming C++

1
Objective
• Understand and use the basic programming constructs of C/C+
+

Introduction to Programming C++


2
• C++ is an object-oriented
programing language, and some
concepts may be new. Take breaks

Introduction to Programming C++


when needed, and go over the
examples as many times as
needed.
3
What is C++?
• C++ is a cross-platform language that can be used to
create high-performance applications.
• C++ was developed by Bjarne Stroustrup, as an extension
to the C language.

Introduction to Programming C++


• C++ gives programmers a high level of control over
system resources and memory.
• The language was updated 3 major times in 2011, 2014,
and 2017 to C++11, C++14, and C++17.

4
Why Use C++
• C++ is one of the world's most popular programming
languages.
• C++ can be found in today's operating systems, Graphical User
Interfaces, and embedded systems.
• C++ is an object-oriented programming language which gives a

Introduction to Programming C++


clear structure to programs and allows code to be reused,
lowering development costs.
• C++ is portable and can be used to develop applications that
can be adapted to multiple platforms.

5
Compilation

Introduction to Programming C++


Program Design

Introduction to Programming C++


Flow Charts
Algorithms and

Introduction to Programming C++


What is an Algorithm?
• An algorithm is a procedure or formula for solving a
problem, based on conducting a sequence of specified
actions.
• A computer program can be viewed as an elaborate

Introduction to Programming C++


algorithm.
• In mathematics and computer science,
an algorithm usually means a small procedure that solves
a recurrent,
• Algorithms are usually presented by using flowcharts.

9
What is a flowchart?
• A flowchart is a diagram that depicts a process, system
or computer algorithm.
• They are widely used in multiple fields to document,
study, plan, improve and communicate often complex

Introduction to Programming C++


processes in clear, easy-to-understand diagrams.
• Flowcharts, use various shapes to depict type of steps
taken: rectangles, ovals, diamonds and potentially
numerous other shapes, along with connecting arrows to
define flow and sequence.

10
What is a flowchart?
• They can range from simple, hand-drawn charts to
comprehensive computer-drawn diagrams depicting
multiple steps and routes.
• Examples of flowcharts:

Introduction to Programming C++


• Business Process Modeling and Notation (BPMN),
• Process Flow Diagram (PFD).
• Data Flow Diagrams (DFDs)
• Unified Modeling Language (UML) Activity Diagrams.

11
Flowcharts Symbols

Introduction to Programming C++


12
Example of a flowchart

Introduction to Programming C++


13
Introduction to
Numeral Systems

Introduction to Programming C++


14
Numeral Systems

• Binary, base 2  Example: (1011)2

Introduction to Programming C++


• Octal, base 8  Example: (17)8
• Decimal, base 10  Example: (25)10
• Hexadecimal, base 16  Example: (34)16

15
Numerical Systems
• Binary system includes the numbers 0 and 1 only
• It has a base of two because it only consists of 2 numbers

• Octal system includes the numbers 0,1,2,3,4,5,6,7

Introduction to Programming C++


• It has a base of 8 because it consists of 8 numbers

• Decimal system includes the numbers 0,1,2,3,4,5,6,7,8,9


• It has a base of 10 because it consists of 10 numbers

• Hexadecimal system includes the numbers and letters


0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
16
• It has a base of 16 because it consists of 16 numbers and letters
Converting Decimal to Binary
• To convert from decimal to binary, keep dividing the decimal
number by 2 and keep tracking the remainder

• Once your last answer is 0 stop your division

Introduction to Programming C++


• Write your last remainder as the first digit from the left and
keep writing the other digits all the way to the right

17
Decimal to Binary Table

Introduction to Programming C++


18
Example
• (14)10 = (-------)2

1- Divide by 2
2- Keep track of the remainder
2 14

Introduction to Programming C++


2 7 ………. 0
2 3 ………. 1 4- The last remainder is the first left digit
of your answer
2 1 ………. 1
2 0 ………. 1

3- Stop when the answer is 0


19
Answer : (1110)2
Example
• (29)10= (-----)2

2 29
2 14 ………. 1

Introduction to Programming C++


2 7 ……..…. 0
2 3 ……..…. 1
2 1 ……..…. 1
2 0 ……..…. 1

• Answer (11101)2
20
Converting Binary to Decimal
• Number the digits from 0 starting from the right digit
10110
4 3 2 1 0
• Consider the digits that hold 1 and ignore the ones with 0

Introduction to Programming C++


10110
4 3 2 1 0
Digits 1, 2 ,4
• Place the digit number of the considered digit as a power to
number 2 and add them
24 + 22 + 21
16 + 4 + 2= 22
21
Example
• (101101)2= (45)10

101101
5 4 3 2 1 0  1- Number the digits

Introduction to Programming C++


5 4 3 2 1 0  2- Consider the digit numbers that have a digit
value of 1, ignore which has a value of 0
25 + 23 + 22 + 20  3- Set the selected digit numbers as a power
to the number 2 and add the values
32 + 8 + 4 + 1= 45  Answer

22
For Practice
• Convert the following:

1. (27)10= (----------)2
2. (35)10= (----------)2

Introduction to Programming C++


3. (48)10= (----------)2

4. (10100)2= (----------)10
5. (110011)2= (----------)10
6. (010110)2= (----------)10

23
Answers
1. 11011
2. 100011
3. 110000

Introduction to Programming C++


4. 20
5. 51
6. 22

24
Shifting to the Right
• Shifting a binary number to the right is equivalent
to dividing it.

• If you shift once to the right , you divide the

Introduction to Programming C++


binary number by 2

• If you shift twice to the right, you divide the


number by 4
25
How to Shift to the Right

Example: The number is 1 0 1


DROP or DELETE the number to the right (drop the Least
Significant Bit, LSB)

Introduction to Programming C++


101 LSB
Answer: 1 0

26
Example Explanation
• The original number was 101 in binary which is
equivalent to 5 in decimal.

• The answer after shifting to the right is 2 in decimal.

Introduction to Programming C++


• That means by shifting one digit to the right the binary
number gets divided by 2 (5/2 = 2 in binary)

27
Shifting to the Left
• Shifting a binary number to the left is equivalent to multiplying
it.

• If you shift once to the left , you multiply the binary number by
2

Introduction to Programming C++


• If you shift twice to the left, you multiply the number by 4

28
How to Shift to the Left

Example: The number is 1 0 1

INSERT a ZERO in the Least Significant Bit (LSB)

Introduction to Programming C++


101
1010 LSB

29
Example Explanation
• The original number was 101 in binary which is equivalent to 5
in decimal.

• The answer after shifting to the left is 10 in decimal.

Introduction to Programming C++


• That means by shifting one digit to the left the binary number
gets multiplied by 2 (5*2=10)

30
For Practice
Solve:
1. (110)2 x (2)10 = ( )2
2. (1011)2 x (4)10 = ( )2
Shift the following numbers twice to the left:

Introduction to Programming C++


3. (111)2= ( )2
4. (1010)2= ( )2
Solve:
5. (110)2 / (2)10 = ( )2
6. (1011)2 / (4)10 = ( )2
Shift the following numbers twice to the right:
7. (111)2= ( )2 31
8. (1010)2= ( )2
Answers:
1. 00001100
2. 00101100
3. 00011100
4. 00101000

Introduction to Programming C++


5. 00000011
6. 00000010
7. 00000001
8. 00000010

32

You might also like