Download presentation
Presentation is loading. Please wait.
Published byNoreen Patrick Modified over 8 years ago
1
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were taken from the materials accompanying Fundamentals of Logic Design, 6 th Edition, by Roth and Kinney, and were used with permission from Cengage Learning.
2
Fall 2010ECE 331 - Digital System Design2 Representation of Negative Numbers (continued)
3
Fall 2010ECE 331 - Digital System Design3 Signed Binary Numbers Three representations for signed binary numbers: 1. Sign and Magnitude 2. 1's Complement 3. 2's Complement
4
Fall 2010ECE 331 - Digital System Design4 1's Complement An n-bit positive number (P) is represented in the same way as in the Sign and Magnitude representation. The sign bit (MSB) = 0. The remaining n-1 bits represent the magnitude.
5
Fall 2010ECE 331 - Digital System Design5 1's Complement An n-bit negative number (N) is represented using the “1's Complement” of the equivalent positive number (P). N' = 1's Complement representation for the negative number N. N' = (2 n – 1) – P where P = |N| The sign bit (MSB) = 1 for all negative numbers using the 1's Complement representation.
6
Fall 2010ECE 331 - Digital System Design6 1's Complement Example: Determine the 1's Complement representation for the following negative numbers, using 8 bits: - 11 - 107 - 74 Hint: (2 n – 1) = (2 8 – 1) = 255
7
Fall 2010ECE 331 - Digital System Design7 1's Complement The 1's Complement representation of N can also be determined using the bit-wise complement of P. N = n-bit negative number P = |N| N' = 1's Complement representation of N. N' = bit-wise complement of P i.e. complement P, bit-by-bit.
8
Fall 2010ECE 331 - Digital System Design8 1's Complement Example: Determine the 1's Complement representation (using the bit-wise complement) for the following negative numbers, using 8 bits: - 74 - 11 - 107
9
Fall 2010ECE 331 - Digital System Design9 1's Complement For an n-bit signed binary number, - (2 n-1 – 1) <= D <= + (2 n-1 – 1) Includes a representation for -0 and +0. Represents an equal number of positive and negative values.
10
Fall 2010ECE 331 - Digital System Design10 1's Complement Given a negative number (N), represented using the 1's Complement representation (N'), the magnitude of the number (P) can be determined as follows: P = (2 n – 1) – N' or P = bit-wise complement of N'
11
Fall 2010ECE 331 - Digital System Design11 2's Complement An n-bit positive number (P) is represented in the same way as in the Sign and Magnitude representation. The sign bit (MSB) = 0. The remaining n-1 bits represent the magnitude.
12
Fall 2010ECE 331 - Digital System Design12 2's Complement An n-bit negative number (N) is represented using the “2's Complement” of the equivalent positive number (P). N* = 2's Complement representation for the negative number N. N* = (2 n ) – P where P = |N| The sign bit (MSB) = 1 for all negative numbers using the 2's Complement representation.
13
Fall 2010ECE 331 - Digital System Design13 2's Complement Example: Determine the 2's Complement representation for the following negative numbers, using 8 bits: - 11 - 107 - 74 Hint: (2 n ) = (2 8 ) = 256
14
Fall 2010ECE 331 - Digital System Design14 2's Complement The 2's Complement representation is related to the 1's Complement representation as follows: N' = (2 n – 1) – P N* = (2 n ) – P N* = N' + 1
15
Fall 2010ECE 331 - Digital System Design15 2's Complement The 2's Complement representation of N can also be determined by adding 1 to the 1's Complement representation of N. N = n-bit negative number P = |N| N' = One's Complement representation of N. N' = bit-wise complement of P. N* = N' + 1
16
Fall 2010ECE 331 - Digital System Design16 2's Complement Example: Determine the 2's Complement representation (using the 1's Complement) for the following negative numbers, using 8 bits: - 74 - 11 - 107
17
Fall 2010ECE 331 - Digital System Design17 2's Complement For an n-bit signed binary number, - (2 n-1 ) <= D <= + (2 n-1 – 1) Includes only one representation for 0. Represents an additional negative value.
18
Fall 2010ECE 331 - Digital System Design18 2's Complement Given a negative number (N), represented using the 2's Complement representation (N*), the magnitude of the number (P) can be determined as follows: P = (2 n ) – N* or P = bit-wise complement of N* + 1
19
Fall 2010ECE 331 - Digital System Design19 Signed Binary Numbers
20
Fall 2010ECE 331 - Digital System Design20 Binary Arithmetic of Signed Binary Numbers
21
Fall 2010ECE 331 - Digital System Design21 2's Complement Addition Addition of n-bit signed binary numbers is straightforward using the 2's Complement system. Addition is carried out in the same way as the addition of n-bit positive numbers. Carry from the sign position (MSB) is ignored. Overflow occurs if the correct result (including the sign) cannot be represented in n bits.
22
Fall 2010ECE 331 - Digital System Design22 2's Complement Addition Example:
23
Fall 2010ECE 331 - Digital System Design23 2's Complement Addition Example:
24
Fall 2010ECE 331 - Digital System Design24 2's Complement Addition Example:
25
Fall 2010ECE 331 - Digital System Design25 2's Complement Addition Exercise: Add the following numbers using 2's Complement Addition: 32 + 45 -17 + 63 Does overflow occur for either addition?
26
Fall 2010ECE 331 - Digital System Design26 Two's Complement Subtraction Subtraction can be implemented using addition. Determine the 2's Complement representation for the negative number -B. Use 2's Complement Addition to add A and -B. A – B = A + (-B)
27
Fall 2010ECE 331 - Digital System Design27 2's Complement Subtraction Exercise: Subtract the following numbers using 2's Complement Addition: 32 – 45 -17 – 63 Does overflow occur for either subtraction?
28
Fall 2010ECE 331 - Digital System Design28 1's Complement Addition Similar to the addition of n-bit numbers using 2's Complement Addition. Instead of discarding the carry from the sign position (MSB), it must be added to the least significant bit (LSB) of the n-bit sum. Referred to as an end-around carry.
29
Fall 2010ECE 331 - Digital System Design29 1's Complement Addition Example:
30
Fall 2010ECE 331 - Digital System Design30 1's Complement Addition Example:
31
Fall 2010ECE 331 - Digital System Design31 1's Complement Addition Exercise: Add the following numbers using 1's Complement Addition: 32 + 45 -17 + 63 Does overflow occur for either addition?
32
Fall 2010ECE 331 - Digital System Design32 Overflow General rule for detecting overflow when adding two n-bit numbers using either 1's Complement or 2's Complement Addition An overflow occurs when the addition of two positive numbers results in a negative value or the addition of two negative numbers results in a positive value. Cannot occur when adding a positive number and a negative number.
33
Fall 2010ECE 331 - Digital System Design33 Binary Codes
34
Fall 2010ECE 331 - Digital System Design34 Binary Codes Weighted Codes Each position in the code has a specific weight Decimal value of code can be determined Unweighted Codes Positions of code do not have a specific weight Decimal value assigned to each code
35
Fall 2010ECE 331 - Digital System Design35 Binary Codes 4-bit Weighted Codes Code:a 3 a 2 a 1 a 0 Weights:w 3, w 2, w 1, w 0 Decimal Value:a 3 x w 3 + a 2 x w 2 + a 1 x w 1 + a 0 x w 0 Examples 8-4-2-1 6-3-1-1 Excess-3 (obtained from 8-4-2-1)
36
Fall 2010ECE 331 - Digital System Design36 Binary Codes Examples of unweighted codes 2-out-of-5 Code Exactly 2 of the 5 bits are “1” for a valid code word. Gray Code Code values for successive decimal digits differ in exactly one bit.
37
Fall 2010ECE 331 - Digital System Design37 Binary Codes
38
Fall 2010ECE 331 - Digital System Design38 Binary Coded Decimal (BCD) 4-bit binary number used to represent each decimal digit. Weighted code:8-4-2-1 Binary values 0000 … 1001 used to represent decimal values 0 … 9. Binary values 1010 … 1111 not used. Very different from binary representation.
39
Fall 2010ECE 331 - Digital System Design39 In the simplest form of binary code, each decimal digit is replaced by its binary equivalent. For example, 937.25 is represented by: Binary Coded Decimal
40
Fall 2010ECE 331 - Digital System Design40 Binary Codes ASCII Code American Standard Code for Information Interchange Common code used for the storage and transfer of alphanumeric characters. 7-bit Weighted Code Can represent a total of 128 characters Used to represent letters, numbers and other characters (e.g. special control characters) Any word or number can be represented (and stored or transferred) using its ASCII Code.
41
Fall 2010ECE 331 - Digital System Design41 ASCII Code (incomplete)
42
Fall 2010ECE 331 - Digital System Design42 Questions?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.