0% found this document useful (0 votes)
7 views61 pages

Lec 4 DigitalLogic

The document provides an overview of digital systems, including types such as combinational and sequential systems, and examples like digital counters and binary multiplication. It discusses the representation of signals, number systems, and methods for converting between different bases, emphasizing the importance of binary values in digital computing. Additionally, it covers binary coding for numeric and non-numeric information, illustrating how data can be uniquely encoded using binary combinations.

Uploaded by

Sahil Ansari
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)
7 views61 pages

Lec 4 DigitalLogic

The document provides an overview of digital systems, including types such as combinational and sequential systems, and examples like digital counters and binary multiplication. It discusses the representation of signals, number systems, and methods for converting between different bases, emphasizing the importance of binary values in digital computing. Additionally, it covers binary coding for numeric and non-numeric information, illustrating how data can be uniquely encoded using binary combinations.

Uploaded by

Sahil Ansari
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/ 61

Logic and Computer Design Fundamentals

Digital Computers and Information

Dr. Joydeep Chandra


Indian Institute of Technology Patna

Adapted from Morris Mano Digital Logic Design, book


25/08/23 1 Indian Institute of Technology Patna
Digital System

Takes a set of discrete information inputs and discrete
internal information (system state) and generates a set of
discrete information outputs.

Discrete Discrete
Inputs Information
Processing Discrete
System Outputs

System State

25/08/23 2 Indian Institute of Technology Patna


Types of Digital Systems

No state present

Combinational Logic System

Output = Function(Input)

State present

State updated at discrete times

Synchronous Sequential System

State updated at any time

Asynchronous Sequential System

State = Function (State, Input)

Output = Function (State) or Function (State, Input)

25/08/23 3 Indian Institute of Technology Patna


Digital System Example:

A Digital Counter (e. g., odometer):

Count Up 0 0 1 3 5 6 4
Reset
I/O
Inputs: Count Up, Reset Components
Outputs: Visual Display
State: "Value" of stored digits

Synchronous or Asynchronous?

25/08/23 4 Indian Institute of Technology Patna


A Digital Computer Example
The binary multiplication table is simple:
00=0 | 10=0 | 01=0 | 11=1
Extending multiplication to multiple digits:
Multiplicand 1011
Multiplier x 101
Partial Products 1011
0000 - MAR
1011 - -
Product 110111
Outputs: CRT,
Inputs: Keyboard, LCD, modem,
mouse, modem, speakers
microphone
Synchronous or Asynchronous?

25/08/23 5 Indian Institute of Technology Patna


Signal

An information variable represented by physical quantity.


For digital systems, the variable takes on discrete values.


Two level, or binary values are the most prevalent values in
digital systems.


Binary values are represented abstractly by:

Digits 0 and 1

Words (symbols) False (F) and True (T)

Words (symbols) Low (L) and High (H)

And words On and Off.


Binary values are represented by values or ranges of
values of physical quantities
25/08/23 6 Indian Institute of Technology Patna
Signal Examples Over Time

Time

Analog Continuous in
value & time

Digital
Discrete in
value & continuous
Asynchronous in time

Discrete in
value & time
Synchronous

25/08/23 7 Indian Institute of Technology Patna


Signal Example – Physical Quantity: Voltage

OUTPUT INPUT
5.0
HIGH HIGH
4.0
3.0 Threshold
2.0 Region
1.0
LOW LOW
0.0
Volts

25/08/23 8 Indian Institute of Technology Patna


Binary Values: Other Physical Quantities

What are other physical quantities represent 0 and
1?


CPU Voltage


Disk Magnetic Field Direction


CD Surface Pits/Light
Control

Dynamic RAM Electrical Charge

25/08/23 9 Indian Institute of Technology Patna


Number Systems – Representation

Positive radix, positional number systems


A number with radix r is represented by a string of digits:
An - 1An - 2 … A1A0 . A- 1 A- 2 … A- m  1 A- m


in which 0 Ai < r and . is the radix point.


The string of digits represents the power series:
i=n-1 j=-1
(Number)r =  Ai r  i
 Aj r j

i=0 j=-m
(Integer Portion) + (Fraction Portion)

25/08/23 10 Indian Institute of Technology Patna


25/08/23 11 Indian Institute of Technology Patna
Number Systems – Examples
General Decimal Binary
Radix (Base) r 10 2
Digits 0 => r - 1 0 => 9 0 =>1
0 r0 1 1
1 r1 10 2
2 r2 100 4
3 r3 1000 8
Powers of 4 r4 10,000 16
r5 100,000 32
Radix 5 r -1 0.1 0.5
-1 r -2 0.01 0.25
-2 r -3 0.001 0.125
-3 r -4 0.0001 0.0625
-4 r -5 0.00001 0.03125
-5

25/08/23 12 Indian Institute of Technology Patna


Special Powers of 2


210 (1024) is Kilo, denoted "K"


220 (1,048,576) is Mega, denoted "M"


230 (1,073, 741,824) is Giga, denoted "G"

25/08/23 13 Indian Institute of Technology Patna


Positive Powers of 2

Useful for Base Conversion

Exponent Value Exponent Value

0 1 11 2048
1 2 12 4096

2 4 13 8192
3 8 14 16384

4 16 15 32768
5 32 16 65536
6 64 17 131072
7 128 18 262144
8 256 19 524288
9 512 20 1048576
10 1024 21 2097152

25/08/23 14 Indian Institute of Technology Patna


Converting Binary to Decimal
• To convert to decimal, use decimal arithmetic to
form S (digit × respective power of 2).
• Example: Convert 110102 to N10:

25/08/23 15 Indian Institute of Technology Patna


Converting Binary to Decimal


To convert to decimal, use decimal arithmetic to form 
(digit × respective power of 2).


Example:Convert 110102 to N10:

25/08/23 16 Indian Institute of Technology Patna


Converting Decimal to Binary

Method 1


Subtract the largest power of 2 (see positive powers of
2 slide) that gives a positive remainder and record the
power.


Repeat, subtracting from the prior remainder and
recording the power, until the remainder is zero.


Place 1’s in the positions in the binary result
corresponding to the powers recorded; in all other
positions place 0’s.

 Example: Convert 62510 to N2


25/08/23 17 Indian Institute of Technology Patna
25/08/23 18 Indian Institute of Technology Patna
Commonly Occurring Bases

Name Radix Digits

2 0,1
Binary

8 0,1,2,3,4,5,6,7
Octal
10 0,1,2,3,4,5,6,7,8,9
Decimal

16 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Hexadecimal

The six letters (in addition to the 10 integers) in
hexadecimal represent:

25/08/23 19 Indian Institute of Technology Patna


Numbers in Different Bases

Good idea to memorize!

Decimal Binary Octal Hexadecimal


Base (10) Base(2) Base(8) Base(16)
00 00000 00 00
01 00001 01 01
02 00010 02 02
03 00011 03 03
04 00100 04 04
05 00101 05 05
06 00110 06 06
07 00111 07 07
08 01000 10 08
09 01001 11 09
10 01010 12 0A
11 01011 13 0B
12 01100 14 0C
13 01101 15 0D
14 01110 16 0E
15 01111 17 0F
16 10000 20 10

25/08/23 20 Indian Institute of Technology Patna


Conversion Between Bases


Method 2


To convert from one base to another

Convert the Integer Part

Convert the Fraction Part

Join the two results with a radix point

25/08/23 21 Indian Institute of Technology Patna


Conversion Details


To Convert the Integral Part:

Repeatedly divide the number by the new radix and save the
remainders. The digits for the new radix are the remainders in
reverse order of their computation. If the new radix is > 10, then
convert all remainders > 10 to digits A, B, …


To Convert the Fractional Part:

Repeatedly multiply the fraction by the new radix and save the
integer digits that result. The digits for the new radix are the integer
digits in order of their computation. If the new radix is > 10, then
convert all integers > 10 to digits A, B, …

25/08/23 22 Indian Institute of Technology Patna


Example: Convert 46.687510 To Base 2

Convert 46 to Base 2


Convert 0.6875 to Base 2:


Join the results together with the radix point:

25/08/23 23 Indian Institute of Technology Patna


Additional Issue - Fractional Part

Note that in this conversion, the fractional part became
0 as a result of the repeated multiplications.


In general, it may take many bits to get this to happen
or it may never happen.

 Example: Convert 0.6510 to N2



0.65 = 0.1010011001001 …

The fractional part begins repeating every 4 steps
yielding repeating 1001 forever!


Solution: Specify number of bits to right of radix point
and round or truncate to this number.

25/08/23 24 Indian Institute of Technology Patna


Checking the Conversion


To convert back, sum the digits times their
respective powers of r.
From the prior conversion of 46.687510
1011102 = 1·32 + 0·16 +1·8 +1·4 + 1·2 +0·1

= 32 + 8 + 4 + 2

= 46

0.10112 = 1/2 + 1/8 + 1/16

= 0.5000 + 0.1250 + 0.062

= 0.6875

25/08/23 25 Indian Institute of Technology Patna


Why Do Repeated Division and Multiplication Work?

Divide the integer portion of the power series on slide 11 by
radix r. The remainder of this division is A0, represented by
the term A0/r.


Discard the remainder and repeat, obtaining remainders
A1…


Multiply the fractional portion of the power series on slide
11 by radix r. The integer part of the product is A-1.


Discard the integer part and repeat, obtaining integer parts
A-2, …


This demonstrates the algorithm for any radix r >1.
25/08/23 26 Indian Institute of Technology Patna
Octal (Hexadecimal) to Binary and Back


Octal (Hexadecimal) to Binary:

Restate the octal (hexadecimal) as three (four) binary digits starting at the radix
point and going both ways.


Binary to Octal (Hexadecimal):

Group the binary digits into three (four) bit groups starting at the radix point and
going both ways, padding with zeros as needed in the fractional part.


Convert each group of three bits to an octal (hexadecimal) digit.

25/08/23 27 Indian Institute of Technology Patna


Octal to Hexadecimal via Binary


Convert octal to binary.


Use groups of four bits and convert as above to
hexadecimal digits.


Example: Octal to Binary to Hexadecimal
6 3 5 . 1 7 7 8


Why do these conversions work?

25/08/23 28 Indian Institute of Technology Patna


Binary Numbers and Binary Coding


Flexibility of representation

Within constraints below, can assign any binary combination
(called a code word) to any data as long as data is uniquely
encoded.

Information Types

Numeric

Must represent range of data needed

Very desirable to represent data such that simple,
straightforward computation for common arithmetic operations
permitted

Tight relation to binary numbers

Non-numeric

Greater flexibility since arithmetic operations not applied.

Not tied to binary numbers
25/08/23 29 Indian Institute of Technology Patna
Non-numeric Binary Codes


Given n binary digits (called bits), a binary code is a
mapping from a set of represented elements to a subset
of the 2n binary numbers. Color Binary
Number
Red 000

Example: A binary code for the seven Yellow 001
colors of the rainbow. Orange 010
Green 011

Code 111 is not used Blue 100
Indigo 101
Violet 110

25/08/23 30 Indian Institute of Technology Patna


Number of Bits Required


Given M elements to be represented by a binary code, the minimum
number of bits, n, needed, satisfies the following relationships:
2n > M > 2(n – 1)
n = log2 M where x , called the ceiling function, is the integer
greater than or equal to x.


Example: How many bits are required to represent decimal digits
with a binary code?

25/08/23 31 Indian Institute of Technology Patna


Number of Elements Represented


Given n digits in radix r, there are rn distinct elements
that can be represented.


But, you can represent m elements, m < rn


Examples:

You can represent 4 elements in radix r = 2 with n = 2 digits: (00, 01, 10,
11).

You can represent 4 elements in radix r = 2 with n = 4 digits: (0001, 0010,
0100, 1000).

This second code is called a "one hot" code.

25/08/23 32 Indian Institute of Technology Patna


Binary Codes for Decimal Digits
 There are over 8,000 ways that you can chose 10 elements
from the 16 binary numbers of 4 bits. A few are useful:

Decimal 8,4,2,1 Excess3 8,4,-2,-1 Gray


0 0000 0011 0000 0000
Properties: 1 0001 0100 0111 0100
2 0010 0101 0110 0101
Sequential 3 0011 0110 0101 0111
Self- 4 0100 0111 0100 0110
Complementary 5 0101 1000 1011 0010
6 0110 1001 1010 0011
7 0111 1010 1001 0001
8 1000 1011 1000 1001
9 1001 1100 1111 1000

25/08/23 33 Indian Institute of Technology


Chapter 1Patna 33
25/08/23 34 Indian Institute of Technology Patna
25/08/23 35 Indian Institute of Technology Patna
Binary Coded Decimal (BCD)


The BCD code is the 8,4,2,1 code.


This code is the simplest, most intuitive binary code for
decimal digits and uses the same powers of 2 as a
binary number, but only encodes the first ten values
from 0 to 9.


Example: 1001 (9) = 1000 (8) + 0001 (1)


How many “invalid” code words are there?


What are the “invalid” code words?

25/08/23 36 Indian Institute of Technology Patna


Excess 3 Code and 8, 4, –2, –1 Code

Decimal Excess 3 8, 4, –2, –1


0 0011 0000
1 0100 0111
2 0101 0110
3 0110 0101
4 0111 0100
5 1000 1011
6 1001 1010
7 1010 1001
8 1011 1000
9 1100 1111


What interesting property is common to these two codes?

25/08/23 37 Indian Institute of Technology Patna


A four-bit binary to Gray code conversion table is as shown below.
Four Bit Binary Number Four Bit Gray Code
B1 B2 B3 B4 G1 G2 G3 G4
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 1
0 0 1 1 0 0 1 0
0 1 0 0 0 1 1 0
0 1 0 1 0 1 1 1
0 1 1 0 0 1 0 1
0 1 1 1 0 1 0 0
1 0 0 0 1 1 0 0
1 0 0 1 1 1 0 1
1 0 1 0 1 1 1 1
1 0 1 1 1 1 1 0
1 1 0 0 1 0 1 0
1 1 0 1 1 0 1 1
1 1 1 0 1 0 0 1
1 1 1 1 1 0 0 0

25/08/23 38 Indian Institute of Technology Patna


The generation of 4-bit Gray code can be calculated by
using formula.
G1 = B1
G2 = B1ÅB2
G3 = B2ÅB3
G4 = B3ÅB4

25/08/23 39 Indian Institute of Technology Patna


The most significant bit (MSB) of the Gray code is always
equal to the MSB of the given binary code other bits of the output
Gray code can be obtained by Xoring binary code bit at that index
and previous index.
The binary to Gray code conversions can be done by using
xoring logic gate. A four-bit binary code converter is shown
above. The input is binary code and the output is equivalent Gray
code.

25/08/23 40 Indian Institute of Technology Patna


Gray to binary code conversion

In Gray to binary conversion, the input is Gray code and


output is its equivalent binary code.
The generation of four-bit binary equivalent code can be
calculated by using formula.
B1 = G1
B2 = G2 Å B1
B3 = G3 Å B2
B4 = G4 Å B3

25/08/23 41 Indian Institute of Technology Patna


 The MSB of binary code is similar to the MSB of Gray code.
 To get next bit, use the xoring operation among the MSB of
binary to the next bit of the Gray code.
 Similarly, to get the third bit, it uses the xoring operation
among the second bit to the third MSB of the Gray code and
so on.

25/08/23 42 Indian Institute of Technology Patna


A four-bit Gray to binary code conversion table is as shown below.
Four Bit Gray Code Four Bit Binary Number
G1 G2 G3 G4 B1 B2 B3 B4
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 1 0 0 1 0
0 0 1 0 0 0 1 1
0 1 1 0 0 1 0 0
0 1 1 1 0 1 0 1
0 1 0 1 0 1 1 0
0 1 0 0 0 1 1 1
1 1 0 0 1 0 0 0
1 1 0 1 1 0 0 1
1 1 1 1 1 0 1 0
1 1 1 0 1 0 1 1
1 0 1 0 1 1 0 0
1 0 1 1 1 1 0 1
1 0 0 1 1 1 1 0
1 0 0 0 1 1 1 1

25/08/23 43 Indian Institute of Technology Patna


Warning: Conversion or Coding?


Do NOT mix up conversion of a decimal number to a binary
number with coding a decimal number with a BINARY
CODE.

 1310 = 11012 (This is conversion)


13  0001|0011 (This is coding)

25/08/23 44 Indian Institute of Technology Patna


Binary Arithmetic

Bit Addition with Carry


Multiple Bit Addition
Single Bit Subtraction with Borrow
Multiple Bit Subtraction
Multiplication
BCD Addition

25/08/23 45 Indian Institute of Technology Patna


Single Bit Binary Addition with Carry

Given two binary digits (X,Y), a carry in (Z) we get the


following sum (S) and carry (C):
Carry in (Z) of 0:
Z 0 0 0 0
X 0 0 1 1
+Y +0 +1 +0 +1
CS 00 01 01 10
Carry in (Z) of 1: Z 1 1 1 1
X 0 0 1 1
+Y +0 +1 +0 +1
CS 01 10 10 11

25/08/23 46 Indian Institute of Technology Patna


Multiple Bit Binary Addition


Extending this to two multiple bit examples:

Carries 0 0
Augend 01100 10110
Addend + 10001 +10111
Sum


Note: The 0 is the default Carry-In to the least significant bit.

25/08/23 47 Indian Institute of Technology Patna


Single Bit Binary Subtraction with Borrow


Given two binary digits (X,Y), a borrow in (Z) we get
the following difference (S) and borrow (B):
Z 0 0 0 0
Borrow in (Z) of 0:
X 0 0 1 1
-Y -0 -1 -0 -1
BS 00 11 01 00

Z 1 1 1 1
Borrow in (Z) of 1:
X 0 0 1 1
-Y -0 -1 -0 -1
BS 11 10 00 11

25/08/23 48 Indian Institute of Technology Patna


Multiple Bit Binary Subtraction


Extending this to two multiple bit examples:

Borrows 0 0
Minuend 10110 10110
Subtrahend - 10010 - 10011
Difference


Notes: The 0 is a Borrow-In to the least significant
bit. If the Subtrahend > the Minuend, interchange
and append a – to the result.

25/08/23 49 Indian Institute of Technology Patna


Binary Multiplication
The binary multiplication table is simple:
00=0 | 10=0 | 01=0 | 11=1
Extending multiplication to multiple digits:
Multiplicand 1011
Multiplier x 101
Partial Products 1011
0000 -
1011 - -
Product 110111

25/08/23 50 Indian Institute of Technology Patna


BCD Arithmetic

Given a BCD code, we use binary arithmetic to add the digits:
8 1000 Eight
+5 +0101 Plus 5
13 1101 is 13 (> 9)

Note that the result is MORE THAN 9, so must be represented
by two digits!
8 1000 Eight
+5 +0101 Plus 5
13 1101 is 13 (> 9)
+0110 so add 6
carry = 1 0011 leaving 3 + cy
0001 | 0011 Final answer (two digits)

To correct the digit, subtract 10 by adding 6 modulo 16.

If the digit sum is > 9, add one to the next significant digit
25/08/23 51 Indian Institute of Technology Patna
BCD Addition Example


Add 2905BCD to 1897BCD showing carries and digit
corrections.

0
0001 1000 1001 0111
+ 0010 1001 0000 0101

25/08/23 52 Indian Institute of Technology Patna


1 1 1 0
0001 1000 1001 0111
+ 0010 1001 0000 0101

0100 10010 1010 1100


+ 0000+ 0110+ 0110+ 0110

0100 1000 0000 0010

25/08/23 53 Indian Institute of Technology Patna


Number systems
• How do we write negative binary numbers?
• Historically: 3 approaches
• Sign-and-magnitude
• Ones-complement
• Twos-complement

• For all 3, the most-significant bit (MSB) is the sign digit


• 0 ≡ positive
• 1 ≡ negative

• twos-complement is the important one


• Simplifies arithmetic
• Used almost universally

25/08/23 54 Indian Institute of Technology Patna


Sign-and-magnitude
• The most-significant bit (MSB) is the sign digit
• 0 ≡ positive
• 1 ≡ negative

• The remaining bits are the number’s magnitude


• Problem 1: Two representations for zero
• 0 = 0000 and also –0 = 1000

• Problem 2: Arithmetic is cumbersome

25/08/23 55 Indian Institute of Technology Patna


Ones-complement
• Negative number: Bitwise complement positive
number
• 0011 ≡ 310
• 1100 ≡ –310

• Solves the arithmetic problem

• Remaining problem: Two representations for


zero
• 0 = 0000 and also –0 = 1111
25/08/23 56 Indian Institute of Technology Patna
Twos-complement
• Negative number: Bitwise complement plus
one
• 0011 ≡ 310
–1 0
• 1101 ≡ –310 –2 1111 0000 +1

–3 1110 0001 +2
• Number wheel 1101 0010
–4 +3
 Only one zero! 1100 0011

– 5 1011 0100 + 4
 MSB is the sign 1010 0101
digit –6 1001 0110 +5
 0 ≡ positive 1000 0111
–7 +6
 1 ≡ negative
–8 +7

25/08/23 57 Indian Institute of Technology Patna


Twos-complement (con’t)
• Complementing a complement of the original
number
• Arithmetic is easy
• Subtraction = negation and addition
• Easy to implement in hardware

25/08/23 58 Indian Institute of Technology Patna


Miscellaneous
• Twos-complement of non-integers
• 1.687510 = 01.10112
• –1.687510 = 10.01012

• Sign extension
• Write +6 and –6 as twos complement
• 0110 and 1010
• Sign extend to 8-bit bytes
• 00000110 and 11111010

• Can’t infer a representation from a number


• 11001 is 25 (unsigned)
• 11001 is –9 (sign magnitude)
• 11001 is –6 (ones complement)
• 11001 is –7 (twos complement)
25/08/23 59 Indian Institute of Technology Patna
Twos-complement overflow
• Summing two positive numbers gives a negative result

• Summing two negative numbers gives a positive result


–1 0 –1 0
–2 1111 0000 + 1 –2 1111 0000 + 1
–3 1110 0001 + 2 –3 1110 0001 + 2
1101 0010 1101 0010
– 4 1100 0011 + 3 – 4 1100 0011 + 3
– 5 1011 0100 + 4 – 5 1011 0100 + 4
1010 0101 1010 0101
–6 1001 0110 + 5 –6 1001 0110 + 5
–7 1000 0111 + 6 –7 1000 0111 + 6
–8 +7 –8 +7

6 + 4 ⇒ –6 –7 – 3 ⇒ +6
• Make sure to have enough bits to handle overflow

25/08/23 60 Indian Institute of Technology Patna


bb

25/08/23 61 Indian Institute of Technology Patna

You might also like