Lecture 2
Lecture 2
and Introduction to
Microprocessor
Dr. Hesham H. Aly
Lecture: 2
Course Content
• Introduction to digital concepts.
• Number systems, operations, and codes.
• Logic gates.
• Boolean algebra and logic simplification
• Functions of combinational logic.
• Decoders, encoders, MUX, DMUX
• Flip-Flops and related devices
• Flip-Flops applications.
• Counters.
• Shift registers.
2
Content
• Numbering systems: Part 2
• Addition
• Subtraction
• Signed Number
• Arithmetic Operations
• Floating Numbers
• Hexadecimal Numbering Systems
• Octal Numbering System
3
Numbering systems: Part 2
4
Binary Addition
0 + 0 = 0 Sum = 0, carry = 0
General Rules for Binary Addition
0 + 1 = 0 Sum = 1, carry = 0
1 + 0 = 0 Sum = 1, carry = 0
1 + 1 = 10 Sum = 0, carry = 1
When an input carry = 1 due to a previous result, the rules are
1 + 0 + 0 = 01 Sum = 1, carry = 0
1 + 0 + 1 = 10 Sum = 0, carry = 1
1 + 1 + 0 = 10 Sum = 0, carry = 1
1 + 1 + 1 = 10 Sum = 1, carry = 1
5
Binary Addition
• Example: Add (7)10 to (21)10 using binary addition
0111
00111 7
10101 21
11100 = 28
Assignment #1 : Write a C program to make binary addition to solve the following (all the given numbers are in decimal):
- 5+20
- 300+50
- 18+18
6
Binary Subtraction
0-0=0
1-1=0
General Rules for Binary Subtraction 1-0=1
10 - 1 = 1 with a borrow of 1
Example 1: Subtract the binary number 10110 from 11011 and show the equivalent decimal subtraction
(22)10 (27)10
Power x 24 x 23 x 22 x 21 x 20
borrow 1 x 23 1 x 23=2 x 22
#1 1 1 0 1 1 (27)10
- #2 1 0 1 1 0 (22)10
1 (5)10
Solution 0 0 1 0
7
Binary Subtraction
Example: Subtract the binary number 00111 from 10101 and show the equivalent decimal subtraction
1 1 1
/ 10101
/ / 21
00111 7
0 1 1 1 0 = 14
8
Binary Subtraction
• We can say that
A – B = A+(-B)
25-12=25+(-12)
9
Signed Numbers
There are several ways to represent signed binary numbers. In all cases, the MSB
in a signed number is the sign bit, that tells you if the number is positive or
negative.
001101=(13)10 101101=(-13)10
11
Signed Number
• 1’s and 2’s complement methods
The 1’s complement of a binary number is just the inverse of the digits. To form the 1’s complement, change all
0’s to 1’s and all 1’s to 0’s.
1 1 0 0 1 0 1 0
0 0 1 1 0 1 0 1
12
Signed Number
• 1’s and 2’s complement methods
The 2’s complement of a binary number is found by adding 1 to the LSB of the 1’s complement.
0 0 1 1 0 1 0 1
Input bits
Carry
Adder
in (add 1)
Output bits (sum)
0 0 1 1 0 1 1 0 13
Signed Number
• 1’s and 2’s complement methods
Negative numbers are written as the 2’s complement of the corresponding positive
number.
14
Signed Numbers
• 1’s and 2’s complement methods
Example : Assuming that the sign bit = -128, show that 11000110 = -58 as a 2’s complement
signed number:
15
Signed Numbers
• 1’s and 2’s complement methods
16
Arithmetic Operations
Self Study Question:
When will overflow occur? And what are the steps to avoid overflow?
17
Arithmetic Operations
Rules for subtraction: 2’s complement the subtrahend and add the numbers. Discard any final carries.
The result is in signed form.
18
Floating Point
1 1 2
• + =
3 3 3
19
Floating Point
Floating point notation is capable of representing very large or small numbers by using a form of
scientific notation. A 32-bit single precision number is illustrated.
20
Floating Point
• How to represent fraction in the 32bit IEEE standard?
1- Convert the decimal number into binary
2- Represent the output of stage one into scientific number
3- Start to fill the 32 bit based on the IEEE standard
1- (43.625)10 = (101011.101)2
2- (101011.101)2 = 1.01011101 * 25
3- Sign bit = 0
Exponent= 5+127=132= (10000100)2
Fraction = 01011101
21
Floating Point
Assignment #2:
Write a C program that convert any number into 32bit IEEE Floating point. Hence express the speed
of light, c, in single precision floating point notation. (c = 0.2998 x 109) in 32bit IEEE Floating point
22
Hexadecimal Numbering System
Decimal Hexadecimal Binary
Hexadecimal uses sixteen characters to represent numbers: the 0 0 0000
numbers 0 through 9 and the alphabetic characters A through F. 1 1 0001
2 2 0010
Large binary number can easily be converted to hexadecimal by 3 3 0011
grouping bits 4 at a time and writing the equivalent hexadecimal 4 4 0100
character. 5 5 0101
6 6 0110
7 7 0111
Example: Express (1A2F)16 in decimal 8 8 1000
Start by writing the column weights: 9 9 1001
4096 256 16 1 10 A 1010
1 A 2 F16 11 B 1011
12 C 1100
1(4096) + 10(256) +2(16) +15(1) = 670310
13 D 1101
14 E 1110
23
15 F 1111
Octal Numbering System Decimal Octal Binary
0 0 0000
Octal uses eight characters the numbers 0 through 7 to represent 1 1 0001
numbers. There is no 8 or 9 character in octal. 2 2 0010
3 3 0011
4 4 0100
Binary number can easily be converted to octal by grouping bits 3 at a 5 5 0101
time and writing the equivalent octal character for each group. 6 6 0110
7 7 0111
8 10 1000
Example: Express 1 001 011 000 001 1102 in octal: 9 11 1001
10 12 1010
11 13 1011
Group the binary number by 3-bits starting from the
12 14 1100
right. Thus, 1130168
13 15 1101
14 16 1110
15 17 1111
24
25
Reference
• Floyd, Thomas L. Digital fundamentals: A systems approach. Pearson
Education Limited, 2014.
• Lectures Slides for Floyd, Thomas L. Digital fundamentals: A systems
approach. Pearson Education Limited, 2014.
26