Professional Documents
Culture Documents
CPP Slide1
CPP Slide1
• First programmer
• Ada Augusta, Countess of Lovelace
• Colleague of Babbage
Computer Systems(hardware +software)
• Hardware -- Parts of a computer you can touch
--Physical components of a computer
• PC
• Workstation
• Mainframe
• Network
• input/output units
• Memory units
• primary, secondary
• fixed, removable
• CPU
Computer Systems(hardware +software)
• Software -- Parts of a computer you cannot touch
-- Programs that run on a computer
• Operating Systems
• Macintosh
• Windows
• Linux
• High-Level Languages
• C++, Java, BASIC
• Compilers
• Source program, object program, Linking
• Editor: Integrated Development Environments (IDE)
• IDEs combine editor, compiler and the execution
environment (usually including a debugger)
Number representation in computers
by Desalegn W. 7
Binary system
Difficult to design a system that works with 10
different voltage levels
• Solution is base-2 (binary) system
• 2 digits/symbols: 0, 1
• Examples: 0, 1, 01, 111, 101010
The position of each digit (bit) in a binary number can
be assigned a weight
by Desalegn W. 8
Binary system
For example: 1011.101
• 1011.101 is a binary number
• 1 is a digit, 0 is a digit
by Desalegn W. 10
Hexadecimal System
• Base-16 system
• 16 symbols: 10 numeric digits and 6 alphabetic
characters
• 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
• Compact way of writing binary system.
• Widely used in computer and microprocessor
applications.
by Desalegn W. 11
Hexadecimal System
Examples: 1C16 , A8516
The position of each digit in a hexadecimal number can be assigned a
weight
For example: 2AF8.98E
by Desalegn W. 12
Octal System
Base-8 system.
8 digits: 0, 1, 2, 3, 4, 5, 6, 7
Convenient way to express binary numbers and codes.
by Desalegn W. 13
Table of Number Systems
by Desalegn W. 14
Conversion between Numbers
by Desalegn W. 15
1. Decimal to Binary
Method 1: Decimal whole number binary number.
o Method: division-by-2
Method 2: Decimal fraction binary number
o Method: multiplication-by-2
by Desalegn W. 16
Method 1: Division-by-2
• Method 1 is used to convert only whole decimal
numbers (no fraction) to binary.
• Repeat the division of the decimal number with 2
until the quotient is 0.
• Remainder of each division determine the binary
number.
• First remainder represent the LSB and the last
remainder is the MSB.
by Desalegn W. 17
Method 1: Division-by-2
Example : Convert 𝟐𝟓𝟏𝟎 to binary
by Desalegn W. 18
Method 2: Multiplication-by-2
Method 3 is used to convert decimal fraction only to binary.
Repeat the multiplication until the fractional part of the product are all
zeros.
The binary number is determined by the first digit in the multiplication
results.
by Desalegn W. 19
Method 2: Multiplication-by-2
Example : Convert 0.3125 to binary
by Desalegn W. 20
2. Binary to Decimal
Only one method is used. That is the sum of weight.
Example 3: Convert 1011.101 to decimal
21
by Desalegn W.
3. Decimal to Hexadecimal
Method used is repeated division by-16.
Repeat the division of the decimal number
with 16 until the quotient is 0.
Remainder of each division determine the
hexadecimal number.
First remainder represent the LSB and the
last remainder is the MSB.
by Desalegn W. 22
Decimal to Hexadecimal
Example : Convert 65010 to hex number
by Desalegn W. 23
4. Hexadecimal to Decimal
Only one method is used. That is the sum of weight.
Example : Convert A8516 to decimal number
by Desalegn W. 24
5. Decimal to Octal
Method used is repeated division by-8.
Repeat the division of the decimal number with
8 until the quotient is 0.
Remainder of each division determine the octal
number.
First remainder represent the LSB and the last
remainder is the MSB.
by Desalegn W. 25
Decimal to Octal
Example : Convert 35910 to octal number
by Desalegn W. 26
6. Octal to Decimal
Only one method is used. That is the sum of weight.
Example 7: Convert 23748 to decimal number
by Desalegn W. 27
7. Binary to Hexadecimal
Step 1: Break the binary number into 4-bit groups, starting
from LSB.
Step 2: Replace each 4-bit with the equivalent
hexadecimal number.
Example 8: Convert 111111000101101001 to hex number
by Desalegn W. 28
8. Hexadecimal to Binary
Step: Replace each digit of the hexadecimal number with
the equivalent 4-bit binary number.
Example 9: Convert CF8E16 to binary number
by Desalegn W. 29
9. Binary to Octal
Step 1: Break the binary number into 3-bit groups, starting
from LSD.
Step 2: Replace each 3-bit group with the equivalent octal
number.
Example 10: Convert 1011110012 to octal
number
by Desalegn W. 30
10. Octal to Binary
Step: Replace each digit of the octal number with the
equivalent 3-bit binary number.
Example : Convert 75268 to binary number
by Desalegn W. 31
Summary of Conversion
by Desalegn W. 32
ASCII Code
American Standard Code for Information Interchange
Used in computers (keyboard and printers) and electronic
equipment
by Desalegn W. 33
ASCII Code
ASCII code has 128 characters and symbols
Represented by 7-bit binary code
Can be considered an 8-bit code with MSB 0.
The first 32 ASCII characters are non-graphic commands
only for control purposes - The ASCII Control
Characters.
E.g.: null, line feed, start of text, escape
Character A is represented by 65.
by Desalegn W. 34
Binary Arithmetic
Binary Addition
Binary Subtraction
Binary Multiplication
Binary Division
by Desalegn W. 35
Binary Addition
Two binary numbers are added by adding each pair of bits together
with carry propagation.
0 + 0 = 0 with a carry of 0
0 + 1 = 1 with a carry of 0
1 + 0 = 1 with a carry of 0
1 + 1 = 10 with a carry of 1
by Desalegn W. 36
Binary Addition
Example 1 : add 1000 & 111
by Desalegn W. 37
Binary Subtraction
Two binary numbers are subtracted by subtracting each pair of bits
together with borrowing, if needed.
0–0=0
1–1=0
1–0=1
10 – 1 = 1
by Desalegn W. 38
Binary Subtraction
Example 1: subtract 11 from 101
by Desalegn W. 39
Binary Multiplication
The procedure is same as decimal multiplication
0x0=0
0x1=0
1x0=0
1x1=1
by Desalegn W. 40
Binary Multiplication
Example: Multiply 101 and 111
by Desalegn W. 41
Binary Division
Step 1. Align the divisor (Y) with the most significant end
of the dividend. Let the portion of the dividend from its
MSB to its bit aligned with the LSB of the divisor be
denoted X.
Step 2. Compare X and Y.
a) If X >= Y, the quotient bit is 1 and
perform the subtraction X-Y.
b) If X < Y, the quotient bit is 0 and do not
perform any subtractions.
Step3.Shift Y one bit to the right and go to step 2.
by Desalegn W. 42
Binary Division
Example: divide 110101 by 111
by Desalegn W. 43
Negative Numbers
Computer must be handle both positive and negative numbers.
A signed binary number consists of both sign and magnitude
information.
3 types of representation:
• Sign and magnitude (least used)
• 1’s complement
• 2’s complement (most important)
by Desalegn W. 44
Sign and Magnitude
The sign bit, i.e. the left-most bit in a signed binary number
o A ‘0’ sign bit indicates a positive number
o A ‘1’ sign bit indicates a negative number
The remaining bits are the magnitude bits.
by Desalegn W. 45
Sign and Magnitude
• Example : Express the decimal number -39 as an 8-bit number in the
sign-magnitude.
• First: Convert 3910 to binary = 1001112
• Second: Add a zero to as the 7th bit = 01001112
Since the decimal is a negative number, the sign bit is 1.
• Therefore, -3910 = 101001112
by Desalegn W. 46
1’s Complement
To find the 1’s complement of a given binary number,
Change all 1s to 0s and all 0s to 1s.
Example : Find the 1’s complement of 10110010
by Desalegn W. 47
2’s Complement
To find the 2’s complement of a given binary number,
Add 1 to the LSB of the 1’s complement
Example 23 : Find the 2’s complement of 10110010
by Desalegn W. 48
Comparison
by Desalegn W. 49
THE END
THANKS
FOR UR ATTENTION
by Desalegn W. 50