Lec 4 DigitalLogic
Lec 4 DigitalLogic
Discrete Discrete
Inputs Information
Processing Discrete
System Outputs
System State
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?
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
OUTPUT INPUT
5.0
HIGH HIGH
4.0
3.0 Threshold
2.0 Region
1.0
LOW LOW
0.0
Volts
CPU Voltage
Disk Magnetic Field Direction
CD Surface Pits/Light
Control
Dynamic RAM Electrical Charge
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)
210 (1024) is Kilo, denoted "K"
220 (1,048,576) is Mega, denoted "M"
230 (1,073, 741,824) is Giga, denoted "G"
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
To convert to decimal, use decimal arithmetic to form
(digit × respective power of 2).
Example:Convert 110102 to N10:
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.
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:
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
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, …
Convert 0.6875 to Base 2:
Join the results together with the radix point:
In general, it may take many bits to get this to happen
or it may never happen.
Solution: Specify number of bits to right of radix point
and round or truncate to this number.
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.6875
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.
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?
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
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?
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.
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?
What interesting property is common to these two codes?
Do NOT mix up conversion of a decimal number to a binary
number with coding a decimal number with a BINARY
CODE.
13 0001|0011 (This is coding)
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.
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
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.
Add 2905BCD to 1897BCD showing carries and digit
corrections.
0
0001 1000 1001 0111
+ 0010 1001 0000 0101
–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
• Sign extension
• Write +6 and –6 as twos complement
• 0110 and 1010
• Sign extend to 8-bit bytes
• 00000110 and 11111010
6 + 4 ⇒ –6 –7 – 3 ⇒ +6
• Make sure to have enough bits to handle overflow