0% found this document useful (0 votes)
11 views32 pages

EEE 241 - Lecture 03 & 04

dld lecture

Uploaded by

zoya351344
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views32 pages

EEE 241 - Lecture 03 & 04

dld lecture

Uploaded by

zoya351344
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

EEE241 Digital Logic Design (DLD)

Lecture 02 – Complements and Binary Codes

Dr. Muhammad Rizwan Azam


COMSATS University Islamabad (CUI) Islamabad, Pakistan.
Lecture Outline

• 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:

• Example for 6-digit decimal numbers:


• 9’s complement is (rn – 1)–N = (106–1)–N = 999999–N
• 9’s complement of 546700 is 999999–546700 = 453299
• Example for 7-digit binary numbers:
• 1’s complement is (rn – 1) – N = (27–1)–N = 1111111–N
• 1’s complement of 1011000 is 1111111–1011000 = 0100111
• Observation:
• Subtraction from (rn – 1) will never require a borrow
• Diminished radix complement can be computed digit-by-digit
1’s Complement
 1’s Complement (Diminished Radix Complement)
 All ‘0’s become ‘1’s
 All ‘1’s become ‘0’s
 Subtract each digit from 1, For binary: 1 – 0 = 1 and 1 – 1 = 0
 Means subtracting any digit from 1 → Inverting it
Example (10110000)2
 (01001111)2
If you add a number and its 1’s complement …

10110000
+ 01001111
11111111
9’s Complement

• 9’s Complement (of a decimal no.)


• Subtract each digit from 9
• Example 1

• Example 2
Radix Complement

The r's complement of an n-digit number N in base r is defined as


rn – N for N ≠ 0 and as 0 for N = 0. Comparing with the (r  1) 's
complement, we note that the r's complement is obtained by adding 1
to the (r  1) 's complement, since rn – N = [(rn  1) – N] + 1.
• Example: Base-10

The 10's complement of 012398 is 987602


The 10's complement of 246700 is 753300
• Example: Base-2 (Leave all least significant 0’s and the first 1
unchanged and replace all other 1’s with 0’s and 0’s with 1’s)

The 2's complement of 1101100 is 0010100


The 2's complement of 0110111 is 1001001
Radix Complement
 2’s Complement
 Take 1’s complement then add 1
 Toggle all bits to the left of the first ‘1’ from the right

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.

Therefore, the answer is – (10's complement of 30718) =  69282.


Subtraction with
Complements
• Example 1.7
• Given the two binary numbers X = 1010100 and Y = 1000011,
perform the subtraction (a) X – Y ; and (b) Y  X, by using 2's
complement.

There is no end carry.


Therefore, the answer is Y
– X =  (2's complement of
1101111) =  0010001.
Subtraction with
Complements
• Subtraction of unsigned numbers can also be done by means
of the (r  1)'s complement.
• Remember that the (r  1) 's complement is one less then the
r's complement.
• The result of adding the minuend to the complement of the
subtrahend produces a sum that is one less than the correct
difference when an end carry occurs.
• Removing the end carry and adding 1 to the sum is referred to
as an end‐around carry.
Subtraction with
Complements
• Example 1.8
• Repeat Example 1.7, but this time using 1's complement.

There is no end carry,


Therefore, the answer is Y –
X =  (1's complement of
1101110) =  0010001.
Representation of a Binary
No.
• In digital System data is stored in form of binary numbers
• There are three methods to represent the binary numbers in
digital systems:
• Unsigned representation
• Signed magnitude representation
• 2’s Complement representation
Unsigned Representation

• All binary numbers are considered positive


• What you have studied so far in Decimal → Binary conversion
• Left bit is Most Significant Bit (MSB) of the number
• Example:
Signed Binary Numbers

• To represent negative integers, we need a notation for


negative values.
• It is customary to represent the sign with a bit placed in the
leftmost position of the number since binary digits.
• The convention is to make the sign bit 0 for positive and 1 for
negative.
• User determines if the no. is signed or unsigned
Signed Magnitude
Representation
• Magnitude is magnitude, does not change with sign

S Magnitude (Binary)

Sign Magnitude
Bin. → Dec.
25
Unsigned
(11001)2

-9
Signed
Signed Complement Representation

• More convenient representation to implement arithmetic


operations in computers
• +ive no. is represented in its original form
• -ive no. is represented by its 2’s Complement

+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

• The addition of two numbers in the signed-magnitude


system follows the rules of ordinary arithmetic.
• If the signs are the same, we add the two magnitudes
and give the sum the common sign.
• If the signs are different, we subtract the smaller
magnitude from the larger and give the difference the
sign of the larger magnitude.
• The addition of two signed binary numbers (with negative
numbers represented in signed-2's-complement form) is
obtained from the addition of the two numbers, including
their sign bits.
• A carry out of the sign-bit position is discarded.
Arithmetic addition

• Example

• Negative numbers must be initially in 2’s‐complement form


• If the sum obtained after the addition is negative, it is in 2’s‐
complement form.
• In each of the four cases, the operation performed is addition
with the sign bit included.
Arithmetic Subtraction

• 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:

( 6)  ( 13) (11111010  11110011)


(11111010 + 00001101)
00000111 (+ 7)
Binary Codes

• Binary is used in machines


• However, humans are more ‘comfortable’ with decimal no.
and alphabets
• Any discrete element of information can be represented with
a binary code (i.e., a pattern of 0’s and 1’s)
• An n-bit binary code is an n-bit word which can represent
up to different elements
• Standard Examples:
• Binary Coded Decimal (BCD)
• Gray Code
• ASCII Code
• Error Detecting Code
BCD Code
• Each decimal digit is coded
separately by 4 bits
• A number with k decimal digits will
require 4k bits in BCD.
• Decimal 396 is represented in BCD
with 12bits as 0011 1001 0110, with
each group of 4 bits representing
one decimal digit.
• A decimal number in BCD is the
same as its equivalent binary
number only when the number is
between 0 and 9.
• The binary combinations 1010
through 1111 are not used and have
no meaning in BCD.
Binary Codes

• Example:
• Consider decimal 185 and its corresponding value in BCD and
binary:
• Remember: Conversion is not same as coding

• BCD is a weighted code (8421)


• Example:

(0110)

8X0 + 4X1 + 2X1 + 1X0

=6
Other Binary Codes

• Many different codes can be formulated by arranging four bits


into 10 distinct combinations.
Gray Code
• It is convenient to use the Gray code to
represent digital data that have been
converted from analog data
• Only bit in the code group changes in going
from one number to the next.
• Error detection.
• Representation of analog data.
• Low power design.
000 001

010 011
100 101

110 111
1-1 and onto!!
ASCII Character Codes

• American Standard Code for Information Interchange


• A popular code used to represent information sent as
character-based data.
• It uses 7-bits to code 128 characters:
• 94 Graphic printing characters.
• 34 Non-printing characters.
• Some non-printing characters are used for text format (e.g.
BS = Backspace, CR = carriage return).
• Other non-printing characters are used for record marking
and flow control (e.g. STX and ETX start and end text areas).
ASCII Code
• American Standard Code for Information Interchange
(ASCII) Character Code

H=(100100
0)
7-bit code (B7B6B5
B4B3B2B1)
Binary Codes

• ASCII Character Code


ASCII Properties

• ASCII has some interesting properties:


• Digits 0 to 9 span Hexadecimal values 30 16 to 3916

• Upper case A-Z span 4116 to 5A16

• Lower case a-z span 6116 to 7A16


• Lower to upper case translation (and vice versa) occurs by flipping bit
6.
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)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy