Digital Logic
Digital Logic
Suresh C
Assistant professor
EEE Dept,RVCE
Outline
• Introduction
• Numbering Systems
• Binary & Hexadecimal Numbers
• Base Conversions
• Binary Addition, Subtraction, Multiplication
• Hexadecimal Addition & Subtraction
• Binary Codes for Decimal Digits
• Character Storage & Parity
Introduction
• Computers only deal with binary data (0s and 1s), hence all data manipulated by computers must
be represented in binary format.
• Machine instructions manipulate many different forms of data:
• Numbers:
• Integers: 33, +128, -2827
• Real numbers: 1.33, +9.55609, -6.76E12, +4.33E-03
• Alphanumeric characters (letters, numbers, signs, control characters): examples: A, a, c, 1 ,3, ", +, Ctrl,
Shift, etc.
• Images (still or moving): Usually represented by numbers representing the Red, Green and Blue (RGB)
colors of each pixel in an image,
• Sounds: Numbers representing sound amplitudes sampled at a certain rate (usually 20kHz).
• So in general we have two major data types that need to be represented in computers; numbers
and characters.
Binary Digit Representation
High = 1
Voltage Level
• Using electric voltage
Unused
• Used in processors and digital circuits
• High voltage = 1, Low voltage = 0 Low = 0
• Using electric charge
• Used in memory cells
• Charged memory cell = 1, discharged memory cell = 0
• Using magnetic field
• Used in magnetic disks, magnetic polarity indicates 1 or 0
• Using light
• Used in optical disks, encodes binary data (bits) in the form of pits (0, no light
reflection when read) and lands (1, due to light reflection when read)
Numbering Systems
• Numbering systems are characterized by their base number.
• In general, a numbering system with a base r will have r different
digits (including the 0) in its number set. These digits will range from
0 to r-1.
• The most widely used numbering systems are listed in the table
below:
Weighted Number Systems
• A number D consists of n digits with each digit having a particular
position.
• Digits to the left of the radix point (integral digits) have positive position
indices, while digits to the right of the radix point (fractional digits) have
negative position indices.
The Radix Point
• Position indices of digits to the left of the radix point (the integral part
of D) start with a 0 and are incremented as we move left (dn-1dn-
2…..d2d1d0).
• Position indices of digits to the right of the radix point (the fractional
part of D) start with a -1 and are decremented as we move right(d-1d-
2…..d-m).
• The weight associated with digit position i is given by wi = ri, where i
is the position index ∀i= -m, -m+1, …, -2, -1, 0, 1, ……, n-1.
• The Value of D is Computed as:
The Radix Point
• Example: Show how the value of the decimal number 52.946 is
estimated.
Notation
• Let (D)r denote a number D expressed in a number system of radix r.
• In this notation, r will be expressed in decimal.
• Examples:
• (29)10 Represents a decimal value of 29. The radix “10” here means
ten.
• (100)16 is a Hexadecimal number since r = “16” here means sixteen.
This number is equivalent to a decimal value of 162=256.
• (100)2 is a Binary number (radix =2, i.e. two) which is equivalent to a
decimal value of 22 = 4.
Binary System
1 1 1 1 1 1 1 1
27 26 25 24 23 22 21 20
• r=2
• Each digit (bit) is either 1 or 0
• Each bit represents a power of 2
• Every binary number is a sum of powers of 2
Some common
powers of 2
Binary System
• Examples: Find the decimal value of the two Binary numbers (101)2
and (1.101)2
Octal System
• r = 8 (Eight = 23 )
• Eight allowed digits {0, 1, 2, 3, 4, 5, 6, 7}
• Examples: Find the decimal value of the two Octal numbers (375)8
and (2.746)8
Hexadecimal System
• r = 16 (Sixteen = 24)
• Sixteen allowed digits {0-to-9 and A, B, C, D, E, F}
• Where: A = Ten, B = Eleven, C = Twelve, D = Thirteen, E = Fourteen & F
= Fifteen.
• Examples: Find the decimal value of the two Hexadecimal numbers
(9E1)16 and (3B.C )16
Hexadecimal Integers
• Binary values are represented in hexadecimal.
Important Properties
• The Largest value that can be expressed in n integral digits is (rn-1).
• In binary: (111)2 = 23 – 1
• In octal: (777)8 = 83 – 1
• In decimal: (999)10 = 103 – 1
• Total number of values (patterns) representable in n digits is rn: 0 to
rn-1
• The Largest value that can be expressed in m fractional digits is (1-r-
m).
stop when
37 = 100101 quotient is zero
Another Procedure for Converting from Decimal to Binary
d = hexadecimal digit
• Examples:
• (1234)16 = (1 163) + (2 162) + (3 161) + (4 160) =
(4,660) 10
• (3BA4)16 = (3 163) + (11 * 162) + (10 161) + (4 160) =
(15,268)10
Converting Decimal to Hexadecimal
❖ Repeatedly divide the decimal integer by 16. Each remainder
is a hex digit in the translated value:
stop when
quotient is zero
(422)10 = (1A6)16
Converting Fractions
• Assume that XB has n digits, XB = (0.b-1 b-2 b-3…….b-n)B
• Assume that XA has m digits, XA = (0.a-1 a-2 a-3…….a-m)A
Converting Fractions
• Example: Convert (0.731)10 to (?)2
Converting Fractions
• Example: Convert (0.731)10 to (?)8
carry: 1
0 0 0 0 0 1 0 0 (4)
+ 0 0 0 0 0 1 1 1 (7)
0 0 0 0 1 0 1 1 (11)
bit position: 7 6 5 4 3 2 1 0
Binary Subtraction
• The borrow digit is negative
and has the weight of the
next higher digit.
Binary Multiplication
• Binary multiplication is performed similar to decimal multiplication.
• Example: 11 * 5 = 55
Multiplication by Shifting Left
❖ What happens if bits are shifted left by 1 bit position?
Before 0 0 0 0 0 1 0 1 =5 Multiplication
After 0 0 0 0 1 0 1 0 = 10 By 2
Before 0 0 0 0 0 1 0 1 =5 Multiplication
After 0 0 0 1 0 1 0 0 = 20 By 4
Before 0 0 1 0 0 1 1 0 = 38 Division
After 0 0 0 1 0 0 1 1 = 19, r=0 By 2
Before 0 0 1 0 0 1 1 0 = 38 Division
After 0 0 0 0 1 0 0 1 = 9, r=2
By 4
carry 1 1 1
9 C 3 7 2 8 6 5
+ 5 + B = 5 + 11 = 16
1 3 9 5 E 8 4 B Since Sum ≥ 16
Sum = 16 – 16 = 0
A F C D 1 0 B 0 Carry = 1
Hexadecimal Subtraction
• Start with the least significant hexadecimal digits
• Let Difference = subtraction of two hex digits
• If Difference is negative
• Difference = 16 + Difference and Borrow = 1
borrow 1 1 1
• Example: 9 C 3 7 2 8 6 5
-
1 3 9 5 E 8 4 B Since 5 < B, Difference < 0
Difference = 16+5–11 = 10
Borrow = 1
8 8 A 1 4 0 1 A
Binary Codes
• How to represent characters, colors, etc.?
• Define the set of all represented elements
• Assign a unique binary code to each element of the set
• Given n bits, a binary code is a mapping from the set of elements to a subset of
the 2n binary numbers
• Coding Numeric Data (example: coding decimal digits)
• Coding must simplify common arithmetic operations
• Tight relation to binary numbers
• Coding Non-Numeric Data (example: coding colors)
• More flexible codes since arithmetic operations are not applied
Example of Coding Non-Numeric Data
• Suppose we want to code 7 colors of the rainbow
❖ Examples:
ASCII code for space character = 20 (hex) = 32 (decimal)
ASCII code for ‘A' = 41 (hex) = 65 (decimal)
ASCII code for 'a' = 61 (hex) = 97 (decimal)
Control Characters
• The first 32 characters of ASCII table are used for control; codes = 00 to 1F
(hexadecimal)
• Examples of Control Characters
• Character 0 is the NULL character used to terminate a string
• Character 9 is the Horizontal Tab (HT) character
• Character 0A (hex) = 10 (decimal) is the Line Feed (LF)
• Character 0D (hex) = 13 (decimal) is the Carriage Return (CR)
• The LF and CR characters are used together
• They advance the cursor to the beginning of next line
• One control character appears at end of ASCII table
• Character 7F (hex) is the Delete (DEL) character
Error Detection
• Binary information may be transmitted through some communication
medium, e.g. using wires or wireless media.
• A corrupted bit will have its value changed from 0 to 1 or vice versa.
• To be able to detect errors at the receiver end, the sender sends an
extra bit (parity bit) with the original binary message.
Parity Bit
• A parity bit is an extra bit included with the n-bit binary message to
make the total number of 1’s in this message (including the parity bit)
either odd or even.
• The 8th bit in the ASCII code is used as a parity bit.
• There are two ways for error checking:
• Even Parity: Where the 8th bit is set such that the total number of 1s in the 8-
bit code word is even.
• Odd Parity: The 8th bit is set such that the total number of 1s in the 8-bit code
word is odd.
7-bit ASCII Character With Even Parity With Odd Parity
‘A’ = 1000001 0 1000001 1 1000001
‘T’ = 1010100 1 1010100 0 1010100
Detecting Errors using Parity
• Parity can detect all single-bit errors
• If even parity is used and a single bit changes, it will change the parity to odd,
which will be detected at the receiver end
• The receiver end can detect the error, but cannot correct it because it does
not know which bit is erroneous
• Can also detect some multiple-bit errors
• Error in an odd number of bits