ELE 2213 Digital Circuits
CLO1 – Use various numbering systems to code digital information
Lecture 3 – (1.3) Determine the true magnitude, 1’s complement, and 2's complement form for
4-bit and 8-bit binary numbers and list common applications of each form.
(1.4) Arithmetic operations for binary numbers (Addition, Subtraction, Multiplication and
division)
Monday, November 18, 2024
2
Reading material
for this lecture
including self-tests
Objectives of and troubleshooting
this lecture
Chapter 10
• Understand binary number
system. Sections 10.1, 10.5, 10.8, and
10.10.
• Know how to convert
between binary, octal,
decimal, and hexadecimal
numbers.
• Know how to take the
complement of a number.
3
Common Powers
Base 10
4
Common Powers
Base 2
What is the value of “k”, “M”, and “G”?
In computing, particularly w.r.t. memory, the base-2 interpretation generally applies
5
1’s Complement
The 1’s complement of a binary number In digital circuits, the 1’s complement is
is just the inverse of the digits. To form formed by using inverters
the 1’s complement, change all 0’s to
1’s and all 1’s to 0’s.
For example, the 1’s complement of
11001010 is
00110101
6
2’s Complement
The 2’s complement of a binary number In digital circuits, the 2’s complement is formed
is found by adding 1 to the LSB of the by using inverters and an adder as follows:
1’s complement.
Recall that the 1’s complement of
11001010 is
00110101
To form the 2’s complement, add 1: Input bits
Carry
Adder
in (add 1)
00110101 (1’s complement) Output bits (sum)
+1
00110110 (2’s complement)
7
Signed Binary Numbers An exam question
There are several ways to represent
signed binary numbers. In all cases, the
MSB in a signed number is the sign Three forms:
bit, that tells you whether the number
is positive or negative. Sign – Magnitude form:
1’s Complement form
2’s Complement form
Positive numbers are stored in true
form (with a 0 for the sign bit) and
negative numbers are stored in
complement form (with a 1 for the sign
bit).
8
Signed Binary NumbeHrs
Example: 58 is written using 8-bits as 00111010 (true form).
• Sign – Magnitude form:
Positive number : 00111010
Negative number : 10111010 -58
• 1’s Complement form: Sign bit Magnitude bits
Positive number : 00111010
Negative number : 11000101 -58
• 2’s Complement form:
Positive number : 00111010
Negative number : 11000110 -58
9
Signed Binary Numbers
An easy way to read a signed number that uses this notation is to assign the sign bit a column
weight of -128 (for an 8-bit number). Then add the column weights for the 1’s.
Example: Assuming that the sign bit = -128, show that 11000110 = -58 as a 2’s complement signed
number:
Solution: Column weights: -128 64 32 16 8 4 2 1.
1 1 0 0 0 1 1 0
-128 +64 +4 +2 = -58
Example2: Show that 10101010 = -86 as a 2’s complement signed number:
Solution2:
Interactive Questions using Nearpod Tool 10
Q1. what is the 1’s complement Q6. Write 46 in negative sign Q10. Convert from 80 base 10 to
of the binary number 10110011? magnitude form over 8 bits base 2. show your work.
Answer: 01001100 Answer: 100101110 (-46)
Q7. Write 69 as positive and
Q2. what is the 1’s complement negative number using 1’s
of the binary number 10111? complement form over 8 bits
Answer: 01000 Answer: 001000101 (69)
110111010 (-69)
Q3. what is the 2’s complement Q8. Write 99 as positive and
of the binary number 100011? negative number using 2’s
Answer: 011100 complement form over 8 bits
+1 Answer: 001100011 (99)
-------------------- 110011101 (-99)
011101 Q9. Given the following 2’s
Q4. what is the 2’s complement complement signed number
of the binary number 100001? 10101010, calculate the equivalent
Answer: 011110 signed decimal number.
+1 Answer: 10101010
-------------------- -128+32+8+2=-86
011111 Verification: performing 2’s
Q5. Write 79 in positive sign complement twice:
magnitude form over 8 bits 01010101
Answer: 001001111 (79) +1
--------------------
01010110 (86)
11
Binary Addition
The rules for binary addition are 0+0=0 Sum = 0, carry = 0
0+1=1 Sum = 1, carry = 0
1+0=1 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 = 11 Sum = 1, carry = 1
12
Binary Addition
Example1: Add the binary numbers
Example2: Add the binary numbers
00111 and 10101 and show the
10101 and 11001 and show the
equivalent decimal addition.
equivalent decimal addition.
Solution1: 0111
Solution2:
00111 7
10101 21
11100 = 28
13
Binary Subtraction 0-0=0
The rules for binary subtraction are 1-1=0
1-0=1
10 - 1 = 1with a borrow of 1
Example1: Subtract the binary Example2: Subtract the binary
number 00111 from 10101 and show number 00111 from 10101 and show
the equivalent decimal subtraction. the equivalent decimal subtraction.
Solution1: 1001 9 Solution2:
0101 5
0100 4
14
Binary Multiplication
The rules for binary multiplication are
Example: multiply the decimal Multiply the binary numbers 1110
numbers 35 and 105 and 1011
Solution: Solution:
15
Arithmetic Operations with Signed Numbers
With n bits, we have 2n combinations. If one bit is used for sign then we have 2 n-1 hence the range
will be –(2n-1) to +(2n-1 -1).
Using the signed number notation with negative numbers in 2’s complement form simplifies
addition and subtraction of signed numbers.
Rules for addition: Add the two signed numbers. Discard any final carries. The result is in
signed form.
Examples:
>0 mag > <0 mag Both negative
00011110 = +30 00001110 = +14 11111111 = -1
00001111 = +15 11101111 = -17 11111000 = -8
00101101 = +45 11111101 = -3 11110111 = -9
Discard carry
16
Arithmetic Operations with Signed Numbers
Note that if the number of bits required for the answer is exceeded, overflow will occur. This
occurs only if both numbers have the same sign. The overflow will be indicated by an incorrect
sign bit (if sign bit of result different from sign bit of numbers added) .
Examples:
01000000 = +64 10000001 = -127
01000001 = +65 10000001 = -127
10000001 = -127 Discard carry 100000010 = +2
Wrong! The answer is incorrect
and the sign bit has changed.
17
Arithmetic Operations with Signed Numbers
Rules for subtraction: 2’s complement the subtrahend and add the numbers. Discard any final
carries. The result is in signed form.
Repeat the examples done previously, but subtract:
Examples:
00011110 (+30) 00001110 (+14) 11111111 (-1)
- 00001111 –(+15) - 11101111 –(-17) - 11111000 –(-8)
2’s complement subtrahend and add:
00011110 = +30 00001110 = +14 11111111 = -1
11110001 = -15 00010001 = +17 00001000 = +8
1 00001111 = +15 00011111 = +31 1 00000111 = +7
Discard carry Discard carry
Interactive Questions using Nearpod Tool 18
Q1. Add the following Q5. Perform the addition Q8. Perform the multiplication operation on
binary numbers: 1+1+1 operation on the following the following binary numbers
Answer: 1+1+1=11, that binary numbers 1011
is sum=1, carry=1. 01010111 x 11
Q2. Add the following + 10010101 ---------------
--------------- 1011
binary numbers: 1+1
Answer: 11101100 + 1011
Answer: 1+1=10, that is Q6. Perform the addition
sum=0, carry=1. --------------
operation on the following Answer: 100001
Q3. Add the following binary numbers
binary numbers: 1+0 Q9. Add the following two signed numbers.
10101010
Answer: 1+0=01, that is 00010100 +20
+ 01010101
+ 11110110 -10
sum=1, carry=0. ---------------
Answer: 11111111
-------------------------------
Q4. Add the following
Q7. Perform the subtraction Answer: 00001010 +10
binary numbers: 0+0
operation on the following Q9. Add the following two signed numbers.
Answer: 0+0=00, that is 11111011 -5
sum=0, carry=0. binary numbers
10101010 + 11111000 -8
- 01010101 -------------------------------
--------------- Answer: 11110011 -13
End Lecture Quiz using Nearpod Tool 19
Q1.
20
Extra Exercises – Selected from Chapter 10 Review Questions
Questions: 10.1, 10.4, 10.9, 10.11 – 10.14.