Lec 1 - Numerical systems
Lec 1 - Numerical systems
1
Objective
• Understand and use the basic programming constructs of C/C+
+
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
5
Compilation
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
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:
11
Flowcharts Symbols
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
17
Decimal to Binary Table
1- Divide by 2
2- Keep track of the remainder
2 14
2 29
2 14 ………. 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
101101
5 4 3 2 1 0 1- Number the digits
22
For Practice
• Convert the following:
1. (27)10= (----------)2
2. (35)10= (----------)2
4. (10100)2= (----------)10
5. (110011)2= (----------)10
6. (010110)2= (----------)10
23
Answers
1. 11011
2. 100011
3. 110000
24
Shifting to the Right
• Shifting a binary number to the right is equivalent
to dividing it.
26
Example Explanation
• The original number was 101 in binary which is
equivalent to 5 in decimal.
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
28
How to Shift to the Left
29
Example Explanation
• The original number was 101 in binary which is equivalent to 5
in decimal.
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:
32