0% found this document useful (0 votes)
38 views63 pages

Digital Logic

Digital Logic Design covers number systems and data representation in computers. It discusses that computers use binary to represent all data as strings of 0s and 1s. It then covers numbering systems like binary, decimal, hexadecimal and their properties. Key concepts covered are weighted number systems, radix/base, and algorithms for converting between different number bases like binary to decimal.

Uploaded by

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

Digital Logic

Digital Logic Design covers number systems and data representation in computers. It discusses that computers use binary to represent all data as strings of 0s and 1s. It then covers numbering systems like binary, decimal, hexadecimal and their properties. Key concepts covered are weighted number systems, radix/base, and algorithms for converting between different number bases like binary to decimal.

Uploaded by

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

Digital Logic DesignI

Introduction to number systems


Data Representation

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.

• Every digit position is associated with a fixed weight.


• If the weight associated with the ith position is wi, then the value of D
is given by:
Example of Weighted Number Systems

• The Decimal number system is a weighted system.


• For integer decimal numbers, the weight of the rightmost digit (at
position 0) is 1, the weight of position 1 digit is 10, that of position 2
digit is 100, position 3 is 1000, etc.
• Thus, w0 = 1, w1 = 10, w2=100, w3 = 1000, etc.
• Example:
• Show how the value of the decimal number 9375
is estimated.
The Radix (Base)
• For digit position i, most weighted number systems use weights (wi)
that are powers of some constant value called the radix (r) or the
base such that wi = ri.
• A number system of radix r, typically has a set of r allowed digits ∈
{0,1, …,(r-1)}.
• The leftmost digit has the highest weight → Most Significant Digit
(MSD).
• The rightmost digit has the lowest weight → Least Significant Digit
(LSD).
The Radix (Base)
• Example: Decimal Number System
• 1. Radix (Base) = Ten
• 2. Since wi = ri, then
• w0 = 100 = 1,
• w1 = 101 = 10,
• w2= 102 = 100,
• w3 = 103 = 1000, etc.
• 3. Number of Allowed Digits is Ten:
• {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
The Radix Point
• A number D of n integral digits and m fractional digits is represented as
shown:

• 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).

• The Largest value that can be expressed in n integral digits and m


fractional digits is (rn -r–m)
Important Properties
• Q. What is the result of adding 1 to the largest digit of some number
system??
• For the decimal number system, (1)10 + (9)10 = (10)10
• For the binary number system, (1)2 + (1)2 = (10)2 = (2)10
• For the octal number system, (1)8 + (7)8 = (10)8 = (8)10
• For the hexadecimal system, (1)16 + (F)16 = (10)16 = (16)10
Important Properties
• Q. What is the largest value representable in 3-integral digits?
• A. The largest value results when all 3 positions are filled with the
largest digit in the number system.
• For the decimal system, it is (999)10
• For the octal system, it is (777)8
• For the hex system, it is (FFF)16
• For the binary system, it is (111)2
• Q. What is the result of adding 1 to the largest 3-digit number?
• For the decimal system, (1)10 + (999)10 = (1000)10 = (103)10
• For the octal system, (1)8+ (777)8 = (1000)8 = (83)10
Important Properties
• In general, for a number system of radix r, adding 1 to the largest n-
digit number = rn.
• Accordingly, the value of largest n-digit number = rn - 1.
Number Base Conversion
• Given the representation of some number (XB) in a number system of
radix B, we need to obtain the representation of the same number in
another number system of radix A, i.e. (XA).
• For a number that has both integral and fractional parts, conversion is
done separately for both parts, and then the result is put together
with a system point in between both parts.
• Converting Whole (Integer) Numbers
• Assume that XB has n digits (bn-1………..b2 b1 b0)B, where bi is a digit in radix B
system, i.e. bi ∈ {0, 1, ….., “B-1”}.
• Assume that XA has m digits (am-1………..a2 a1 a0)A, where ai is a digit in radix A
system, i.e. ai ∈ {0, 1, ….., “A-1”}.
Converting Whole (Integer) Numbers
• Dividing XB by A, the remainder will be a0.

• In other words, we can write XB = Q0.A+a0


Converting Whole (Integer) Numbers
Converting Whole (Integer) Numbers
• This division procedure can be used to convert an integer value from
some radix number system to any other radix number system.
• The first digit we get using the division process is a0, then a1, then a2,
till am-1
• Example: Convert (53)10 to (?)2
Converting Whole (Integer) Numbers
• Since we always divide by the radix, and the quotient is re-divided
again by the radix, the solution table may be compacted into 2
columns only as shown:
Converting Whole (Integer) Numbers
• Example: Convert (755)10 to (?)8

• Example: Convert (1606)10 to (?)12


Converting Binary to Decimal
• Weighted positional notation shows how to calculate
the decimal value of each binary bit:
Decimal = (dn-1  2n-1) + (dn-2  2n-2) + ... + (d1  21) +
(d0  20)
d = binary digit
• binary 10101001 = decimal 169:
(1  27) + (1  25) + (1  23) + (1  20) =
128+32+8+1=169
Convert Unsigned Decimal to Binary
• Repeatedly divide the decimal integer by 2. Each
remainder is a binary digit in the translated value:

least significant bit

most significant bit

stop when
37 = 100101 quotient is zero
Another Procedure for Converting from Decimal to Binary

• Start with a binary representation of all 0’s.


• Determine the highest possible power of two that is less than or
equal to the number.
• Put a 1 in the bit position corresponding to the highest power of two
found above.
• Subtract the highest power of two found above from the number.
• Repeat the process for the remaining number.
Another Procedure for Converting from Decimal to Binary

• Example: Converting (76)10 to Binary


• The highest power of 2 less than or equal to 76 is 64, hence the seventh
(MSB) bit is 1
• Subtracting 64 from 76 we get 12.
• The highest power of 2 less than or equal to 12 is 8, hence the fourth bit
position is 1
• We subtract 8 from 12 and get 4.
• The highest power of 2 less than or equal to 4 is 4, hence the third bit position
is 1
• Subtracting 4 from 4 yield a zero, hence all the left bits are set to 0 to yield
the final answer
Conversion for Numbers Close to Powers of 2
• There is an efficient way for converting numbers that are close to powers
of 2.
• For example, let us consider converting the decimal number 28 to binary
• 28 is close to 2^5=32. We know that 31=11111
• The difference between 28 and 31 is 3. Thus, we subtract 3 from 31 and we get
11100.
• As another example, let us consider converting the decimal number 1000
to binary
• 1000 is close to 2^10=1024. We know that 1023=1111111111
• The difference between 1023 and 1000 is 23. 23 is represent as 10111. Thus, we
subtract 23 from 1023 and we get 1111101000
Binary to Octal Conversion
• Each octal digit corresponds to 3 binary bits.

• Example: Convert (1110010101.1011011)2 into Octal.


Binary to Hexadecimal Conversion
• Each hexadecimal digit corresponds to 4 binary bits.

• Example: Convert (1110010101.1011011)2 into hex.


Converting Hexadecimal to Binary
• Each Hexadecimal digit can be replaced by its 4-bit binary number to
form the binary equivalent.
Converting Hexadecimal to Decimal
• Multiply each digit by its corresponding power of 16:
Decimal = (d3  163) + (d2  162) + (d1  161) + (d0  160)

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:

least significant digit

most significant digit

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

• Example: Convert (0.357)10 to (?)12


Binary Addition
• 1 + 1 = 2, but 2 is not
allowed digit in binary
• Thus, adding 1 + 1 in the
binary system results in a
Sum bit of 0 and a Carry
bit of 1.
Binary Addition
• Start with the least significant bit (rightmost bit)
• Add each pair of bits
• Include the carry in the addition, if present

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

❖ What happens if bits are shifted left by 2 bit positions?

Before 0 0 0 0 0 1 0 1 =5 Multiplication
After 0 0 0 1 0 1 0 0 = 20 By 4

❖ Shifting Bits Left by n bit positions is multiplication by 2n


❖ As long as we have sufficient space to store the bits
Division by Shifting Right
• What happens if bits are shifted right by 1 bit position?

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

❖ What happens if bits are shifted right by 2 bit positions?

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

❖ Shifting Bits to the Right by n bit positions is division by 2n


❖ The remainder r is the value of the bits that are shifted out
Hexadecimal Addition
• Start with the least significant hexadecimal digits
• Let Sum = summation of two hex digits
• If Sum is greater than or equal to 16
• Sum = Sum – 16 and Carry = 1
• Example:

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

• As a minimum, we need 3 bits to define 7 unique values


Color 3-bit code
• 3 bits define 8 possible combinations Red 000
Orange 001
• Only 7 combinations are needed Yellow 010
Green 011
• Code 111 is not used Blue 100
Indigo 101
• Other assignments are also possible Violet 110
Minimum Number of Bits Required
• Given a set of M elements to be represented by a binary code, the
minimum number of bits, n, should satisfy:
2(n - 1) < M ≤ 2n
n = log2 M where x , called the ceiling function, is the integer greater
than or equal to x
• How many bits are required to represent 10 decimal digits with a binary
code?
• Answer: log2 10 = 4 bits can represent 10 decimal digits
Binary Codes for Decimal Digits
• Internally, digital computers operate on binary numbers.
• When interfacing to humans, digital processors, e.g. pocket
calculators, communication is decimal-based.
• Input is done in decimal then converted to binary for internal
processing.
• For output, the result has to be converted from its internal binary
representation to a decimal form.
• To be handled by digital processors, the decimal input (output) must
be coded in binary in a digit by digit manner.
Binary Codes for Decimal Digits
• For example, to input the decimal number 957, each digit of the number is
individually coded and the number is stored as 1001_0101_0111.
• Thus, we need a specific code for each of the 10 decimal digits. There is a
variety of such decimal binary codes.
• One commonly used code is the Binary Coded Decimal (BCD) code which
corresponds to the first 10 binary representations of the decimal digits 0-9.
• The BCD code requires 4 bits to represent the 10 decimal digits.
• Since 4 bits may have up to 16 different binary combinations, a total of 6
combinations will be unused.
• The position weights of the BCD code are 8, 4, 2, 1.
Binary Codes for Decimal Digits
• Other codes use position weights of
• 8, 4, -2, -1
• 2, 4, 2, 1.
• An example of a non-weighted code is the excess-3 code
• digit codes are obtained from their binary equivalent after adding 3.
• Thus the code of a decimal 0 is 0011, that of 6 is 1001, etc.
Binary Codes for Decimal Digits
Number Conversion versus Coding
• Converting a decimal number into binary is done by repeated division
(multiplication) by 2
• Coding a decimal number into its BCD code is done by replacing each
decimal digit of the number by its equivalent 4 bit BCD code.
• Example: Converting (13)10 into binary, we get 1101, coding the same
number into BCD, we obtain 00010011.
• Exercise: Convert (95)10 into its binary equivalent value and give its
BCD code as well.
• Answer: (1011111)2, and 1001 0101.
Character Storage
• Character sets
• Standard ASCII: 7-bit character codes (0 – 127)
• Extended ASCII: 8-bit character codes (0 – 255)
• Unicode: 16-bit character codes (0 – 65,535)
• Unicode standard represents a universal character set
• Defines codes for characters used in all major languages
• Used in Windows-XP: each character is encoded as 16 bits
• Arabic codes: from 0600 to 06FF (hex)
• UTF-8: variable-length encoding used in HTML
• Encodes all Unicode characters
• Uses 1 byte for ASCII, but multiple bytes for other characters
ASCII Codes

❖ 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

7-bit ASCII character + 1 Parity bit


Sender Receiver
Sent ‘A’ = 01000001, Received ‘A’ = 01000101

You might also like