EEE 241 - Lecture 03 & 04
EEE 241 - Lecture 03 & 04
• Complements
• Diminished Radix (r-1’s) Comp.
• Radix (r’s) Comp.
• Subtraction with Complements
• Signed Binary Numbers
Complements
• There are two types of complements for each base-r system: the radix
complement and diminished radix complement.
• Diminished Radix Complement - (r-1)’s Complement
• Given a number N in base r having n digits, the (r–1)’s complement of N is
defined as:
10110000
+ 01001111
11111111
9’s Complement
• Example 2
Radix Complement
OR
Example:
Number: 10110000 10110000
1’s Comp.:
01001111
+ 1
01010000 01010000
Subtraction with
Complements
• The subtraction of two n-digit unsigned numbers M – N in
base r can be done as follows:
M
N
Subtraction with
Complements
• Example 1.5
• Using 10's complement, subtract 72532 – 3250.
• Example 1.6
• Using 10's complement, subtract 3250 – 72532.
There is no end
carry.
S Magnitude (Binary)
Sign Magnitude
Bin. → Dec.
25
Unsigned
(11001)2
-9
Signed
Signed Complement Representation
+9 0000 1001
Unsigned
1000 1001
Signed Magnitude
-9 11110110
1’s Complement
11110111
2’s Complement
Signed Binary Numbers
Signed One’s Signed Two’s
Decimal Signed Magnitude
Complement Complement
+7 0111 0111 0111
+6 0110 0110 0110
+5 0101 0101 0101
+4 0100 0100 0100
+3 0011 0011 0011
+2 0010 0010 0010
+1 0001 0001 0001
+0 0000 0000 0000
-0 1000 1111 –
-1 1001 1110 1111
-2 1010 1101 1110
-3 1011 1100 1101
-4 1100 1011 1100
-5 1101 1010 1011
-6 1110 1001 1010
-7 1111 1000 1001
Arithmetic addition
• Example
• In 2’s-complement form:
1. Take the 2’s complement of the subtrahend (including the sign bit)
and add it to the minuend (including sign bit).
2. A carry out of sign-bit position is discarded.
( A) ( B ) ( A) ( B )
( A) ( B ) ( A) ( B )
• Example:
• Example:
• Consider decimal 185 and its corresponding value in BCD and
binary:
• Remember: Conversion is not same as coding
(0110)
=6
Other Binary Codes
010 011
100 101
110 111
1-1 and onto!!
ASCII Character Codes
H=(100100
0)
7-bit code (B7B6B5
B4B3B2B1)
Binary Codes
• Error-Detecting Code
• To detect errors in data communication and processing, an eighth
bit is sometimes added to the ASCII character to indicate its
parity.
• A parity bit is an extra bit included with a message to make the
total number of 1's either even or odd.
• Example:
• Consider the following two characters and their even and odd
parity:
• In each case, the extra inserted bit (parity) leads (in total) to even
no. of 1’s
Binary Codes
• Error-Detecting Code
• Redundancy (e.g. extra information), in the form of extra bits, can
be incorporated into binary code words to detect and correct
errors.
• A simple form of redundancy is parity, an extra bit appended onto
the code word to make the number of 1’s odd or even. Parity can
detect all single-bit errors and some multiple-bit errors.
• A code word has even parity if the number of 1’s in the code word
is even.
• A code word has odd parity if the number of 1’s in the code word
is odd.
• Example:
Message A: 100010011 (even parity)
Message B: 10001001 0 (odd parity)