ECE240-Set 2
-
Upload
mahanthesh-monty -
Category
Documents
-
view
116 -
download
0
Transcript of ECE240-Set 2
Synopsys University Courseware – ECE 240Lecture Set 2 – Numbers
ECE 240 -Introduction to Logic Design
Synopsys University Courseware – ECE 240Lecture Set 2 – 2
Number Systems and Codes
Positional number systemsPositional number systems Positional number system conversionsPositional number system conversions Binary system operationsBinary system operations Encoding techniquesEncoding techniques
Synopsys University Courseware – ECE 240Lecture Set 2 – 3
Positional Number System
General form of a number:
dp-1dp-2…d0.d-1d-2..d-n
The value of the number:
Radix Radix PointPoint
Most significant digit (MSB)Most significant digit (MSB) Least significant digit Least significant digit (LSB)(LSB)
ip
ni
i rdD
1
Radix or BaseRadix or Base
Synopsys University Courseware – ECE 240Lecture Set 2 – 4
Decimal System
d : 0, 1, 2, . . . , 9 r = 10
dd33
dd22 dd11 dd00
dd-1-1
dd-2-2
1x101x1033
4x104x1022
5x105x1011 3x103x1000
0x100x10-1-1
5x105x10--
22
1x101x1033 + 4x10 + 4x1022 + 5x10 + 5x1011 + 3x10 + 3x1000 + 0x10 + 0x10-1-1 + 5x10 + 5x10-2 -2 = =
1453.051453.05
p p = 4 , = 4 , n n = 2= 2 1453.01453.055
Synopsys University Courseware – ECE 240Lecture Set 2 – 5
b : 0 , 1 r = 2
bb33
bb22 bb11 bb00
bb-1-1
bb-2-2
1x21x233
1x21x222 0x20x211
1x21x200
0x20x2--
11
1x21x2-2-2
1x21x233 + 1x2 + 1x222 + 0x2 + 0x211 + 1x2 + 1x200 + 0x2 + 0x2-1-1 + 1x2 + 1x2-2-2 = =
13.2513.25
p p = 4 , = 4 , n n = 2= 2 1101.01101.011
Binary System
Synopsys University Courseware – ECE 240Lecture Set 2 – 6
Exercise
Calculate the equivalent decimal numbers:
1122
101022
111122
10010022
1011101122
1x1x2200 = 1 = 1
1x1x2211 + + 0x0x220 0 = 2 + 0 = 2= 2 + 0 = 2
1x1x2211 + + 1x1x2200 = 2 + 1 = 3 = 2 + 1 = 3
1x1x2222 + + 0x0x2211 + + 0x0x2200 = 4 + 0 + 0 = 4 = 4 + 0 + 0 = 4
1x1x2233 + + 0x0x222 2 + + 1x1x2211 + + 1x1x2200 = 8 + 0 + 2 + 1 = 11 = 8 + 0 + 2 + 1 = 11
Synopsys University Courseware – ECE 240Lecture Set 2 – 7
Octal and Hexadecimal Numbers
Octal number System:
r = 8 d : 0, 1, 2, … , 7
Hexadecimal number System:
r = 16 d : 0, 1, 2, …, 9, A, B, C, D, E, F
Used for representations of long binary numbers
Synopsys University Courseware – ECE 240Lecture Set 2 – 8
Binary, Decimal, Octal and Hex #sDecimal Binary Octal Hexadecimal0 0000 00 01 0001 01 12 0010 02 23 0011 03 34 0100 04 45 0101 05 56 0110 06 67 0111 07 78 1000 10 89 1001 11 910 1010 12 A11 1011 13 B12 1100 14 C13 1101 15 D14 1110 16 E15 1111 17 F
Synopsys University Courseware – ECE 240Lecture Set 2 – 9
Binary – Octal Conversion
Starting from the decimal point: Separate the bits into groups of three Replace each group with its corresponding Octal digit
100100011011110110 .. 101101010122 ==
100 100 011011 110110 . . 101101 01001022 = =
436 . 52436 . 5288
Synopsys University Courseware – ECE 240Lecture Set 2 – 10
110001000111101110 .. 101010101122 = =
00010001 00010001 11101110 .. 10101010 1000100022 = =
11E . A811E . A81616
Starting from the decimal point: Separate the bits into groups of four Replace each group with its corresponding
Hexadecimal digit
Binary - Hexadecimal Conversion
Synopsys University Courseware – ECE 240Lecture Set 2 – 11
Octal - Binary Conversion
Convert each Octal digit into its corresponding three bit string
436 . 52436 . 528 8 ==
100100 011011 110110 . 101. 101 01001022
Synopsys University Courseware – ECE 240Lecture Set 2 – 12
Convert each Hexadecimal digit into its corresponding four bit string
A5E . C8A5E . C816 16 ==
10101010 01010101 11101110 . 1100. 1100 1000100022
Hexadecimal - Binary Conversion
Synopsys University Courseware – ECE 240Lecture Set 2 – 13
Radix-r to Decimal Conversion
ip
ni
i rdD
1
Synopsys University Courseware – ECE 240Lecture Set 2 – 14
Decimal to Radix-r Conversion
Successive division of D by r
The remainder of the long division will give the digits starting from the least significant digit
Synopsys University Courseware – ECE 240Lecture Set 2 – 15
Decimal to Binary Conversion
4510
45/2 = 22 The remainder is 1 LSB22/2 = 11 0
11/2 = 5 15/2 = 2 1
2/2 = 1 01/2 = 0 1 MSB
MSBMSBLSBLSB
3232 1616 88 44 22 11
11 00 11 11 00 11
Synopsys University Courseware – ECE 240Lecture Set 2 – 16
Exercises
Convert 5 into binary:Convert 5 into binary: 1 0 11 0 1
Convert 17 into binary:Convert 17 into binary: 1 0 0 0 11 0 0 0 1
Convert 34 into binary:Convert 34 into binary: 1 0 0 0 1 01 0 0 0 1 0
2222
hexadecimal:hexadecimal: 55
hexadecimal:hexadecimal: 1111
hexadecimal:hexadecimal:
Synopsys University Courseware – ECE 240Lecture Set 2 – 17
Binary Addition
Binary addition table:
carry in X Y X+Y carry out 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1
Synopsys University Courseware – ECE 240Lecture Set 2 – 18
Example:
1 0 1 0 1
0 1 1 0 0
1 0 0 0 0 1
2121
1212
3333
16 8 4 2 116 8 4 2 1
Synopsys University Courseware – ECE 240Lecture Set 2 – 19
Binary Subtraction
Binary subtraction table:
barrow in X Y X-Y barrow out
0 0 0 0 0 0 0 1 1 1 0 1 0 1 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1 1 1
Synopsys University Courseware – ECE 240Lecture Set 2 – 20
Example:
1 1 0 1 0
0 1 1 1 1
0 1 0 1 1
2626
1515
1111
16 8 4 2 116 8 4 2 1
Synopsys University Courseware – ECE 240Lecture Set 2 – 21
Representation of Negative Numbers in Binary Systems
Signed-magnitude Representation.
Two’s-Complement Representation.
One’s-Complement Representation.
Synopsys University Courseware – ECE 240Lecture Set 2 – 22
Signed Magnitude Representation
The MSB represents the sign bit (0 = positive, 1 = negative)
The range for n-bit is from - 2n-1 – 1 to +2n-1 – 1.
Example: n=5, Range from -15 to 15 00000 = 0 , 10000 = -0 10011 = -3 , 01100 = +12
Disadvantages: Complicated digital adders Two possible representations of zero
Synopsys University Courseware – ECE 240Lecture Set 2 – 23
Two’s Complement Representation The MSB represents the sign bit (0 = positive, 1 =
negative)
To calculate the negative number:
1. Complement all bits of the positive number
2. Add 1
For n-bit number the decimal value =
B b bi
i
ni
nn
0
2
112 2
The range for n-bit is: The range for n-bit is: from -2from -2n-1 n-1 to +2to +2n-1 n-1 – 1.– 1.
AdvantagesAdvantages: Addition/subtraction performed directly and only : Addition/subtraction performed directly and only one zeroone zero
DisadvantageDisadvantage: One extra negative number (not symmetric): One extra negative number (not symmetric)
Synopsys University Courseware – ECE 240Lecture Set 2 – 24
Two’s Complement Example
N = 8: from -128(10000000) to 127 (01111111)N = 8: from -128(10000000) to 127 (01111111)
001010 = = 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0
1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 step step 11
+ 1+ 1 step step 22
1 0 0 0 0 0 0 0 0 = 01 0 0 0 0 0 0 0 0 = 01010
0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 = 0 = 01010
Synopsys University Courseware – ECE 240Lecture Set 2 – 25
1 0 0 1 1 0 1 11 0 0 1 1 0 1 1
+ 1+ 1
+100+1001010 = = 0 1 1 0 0 1 0 00 1 1 0 0 1 0 0
1 0 0 1 1 1 0 0 = -1001 0 0 1 1 1 0 0 = -1001010
64 32 16 8 4 2 164 32 16 8 4 2 1
step 1step 1step 2step 2
Two’s Complement Example
Synopsys University Courseware – ECE 240Lecture Set 2 – 26
One’s Complement Representation The MSB represents the sign bit (0 = positive, 1 =
negative) To calculate the negative number, complement all
bits of the positive number For n-bit number the decimal value =
B b bi
i
ni
nn
0
2
112 2 1( )
The range for n-bit is: from 2The range for n-bit is: from 2n-1 n-1 – 1 to +2– 1 to +2n-1 n-1 – 1. – 1. AdvantagesAdvantages: Symmetry, ease of : Symmetry, ease of complementation.complementation.
DisadvantagesDisadvantages: : Two possible representations of zero. Two possible representations of zero. Complicated digital adders. Complicated digital adders.
Synopsys University Courseware – ECE 240Lecture Set 2 – 27
One’s-Complement Example
N = 8: form -127(10000000) to 127 (01111111)
+10010 = 0 1 1 0 0 1 0 0
-10010 = 1 0 0 1 1 0 1 1
010 = 0 0 0 0 0 0 0 0
-010 = 1 1 1 1 1 1 1 1
Synopsys University Courseware – ECE 240Lecture Set 2 – 28
Comparison (4-bit) Decimal Signed One’s Two’s
Magnitude Compl.Compl.-8 - - 1000-7 1111 1000 1001-6 1110 1001 1010-5 1101 1010 1011-4 1100 1011 1100 -3 1011 1100 1101 -2 1010 1101 1110 -1 1001 1110 11110 0000 or 1000 0000 or 1111 0000 1 0001 0001 0001
2 0010 0010 0010 3 0011 0011 0011 4 0100 0100 0100 5 0101 0101 0101 6 0110 0110 0110 7 0111 0111 0111
Synopsys University Courseware – ECE 240Lecture Set 2 – 29
Exercise
What is the representation of What is the representation of +11+11, , -11-11 in: in:
5-bit 5-bit signedsigned magnitude representation magnitude representation
0 1 0 1 10 1 0 1 1+11 = +11 =
5-bit 5-bit one’sone’s complement representation complement representation
0 1 0 1 10 1 0 1 1+11 = +11 =
1 1 0 1 11 1 0 1 1-11 = -11 =
1 0 1 0 01 0 1 0 0-11 = -11 =
5-bit 5-bit two’stwo’s complement representation complement representation
0 1 0 1 10 1 0 1 1+11 = +11 = 1 0 1 0 11 0 1 0 1-11 = -11 =
Synopsys University Courseware – ECE 240Lecture Set 2 – 30
Two’s Complement Addition (A+B)
1. Use binary addition rules
2. Ignore any carry beyond the sign bit If the range is not exceeded, addition result
will be correct including the sign bit.
Examples:
(-6) 1 1 0 1 0(-6) 1 1 0 1 0 (0) 1 0 0 0 0 (0) 1 0 0 0 0
(-2) 1 1 1 0(-2) 1 1 1 0
+ (-4) 1 1 0 0+ (-4) 1 1 0 0
(-3) 1 1 0 1(-3) 1 1 0 1
+ (+3) 0 0 1 1+ (+3) 0 0 1 1
Synopsys University Courseware – ECE 240Lecture Set 2 – 31
Two’s Complement Subtraction: Method 1 (a-b)
1. Use binary Subtraction rules
2. Ignore any borrow beyond the sign bit
Example:
(-2) 1 1 1 0(-2) 1 1 1 0
(2) 0 0 1 0 (2) 0 0 1 0
- (4) 0 1 0 0- (4) 0 1 0 0
Synopsys University Courseware – ECE 240Lecture Set 2 – 32
Two’s Complement Subtraction Method 2 (a+(-b)) Add A to the Two’s complement of B:
1. Take the One’s complement of B
2. Add it to A with initial carry-in i.e. 1
Example: 2-4
(-2) 1 1 1 0(-2) 1 1 1 0
11
0 0 1 0 0 0 1 0
+ 1 0 1 1+ 1 0 1 1
One’s Complement of One’s Complement of 44
22
Initial Carry Initial Carry inin
Synopsys University Courseware – ECE 240Lecture Set 2 – 33
Coding
Coding: Representing a set of objects by a set of strings.
Code: The set of bit strings. Code Word: A particular bit string in the Code.
Examples: Data Objects: Decimal Numbers, Characters. Nondata Objects: Machine states, Control Actions.
Synopsys University Courseware – ECE 240Lecture Set 2 – 34
Binary Codes For Decimal Numbers
To represent the 10 decimal digits, we need 4 bits.
Examples: 4 bits Codes
1. BCD (8421) - Binary Coded Decimal
2. 2421
3. Excess-3
Synopsys University Courseware – ECE 240Lecture Set 2 – 35
Decimal CodesDecimal BCD BCD Excess-3
(8421) 2421
0 0000 0000 0011
1 0001 0001 0100
2 0010 0010 0101
3 0011 0011 0110
4 0100 0100 0111
5 0101 1011 1000
6 0110 1100 1001
7 0111 1101 1010
8 1000 1110 1011
9 1001 1111 1100
Synopsys University Courseware – ECE 240Lecture Set 2 – 36
Exercise
Codes for 517
BCD: BCD:
2421:2421:
Excess-3:Excess-3:
0101 0001 01110101 0001 0111
1011 0001 11011011 0001 1101
1000 0100 10101000 0100 1010
Synopsys University Courseware – ECE 240Lecture Set 2 – 37
Gray Code
Decimal Binary Code Gray Code0 000 0001 001 0012 010 0113 011 0104 100 1105 101 1116 110 1017 111 100
ApplicationApplication: Electromechanical applications.: Electromechanical applications.
The Mechanical Encoding disk. Altimeters. - The Mechanical Encoding disk. Altimeters. - is an instrument used to measure the altitude of an object above a fixed level
One bit changes between two successive code One bit changes between two successive code wordswords
Binary Code and Gray Code (n = 3):Binary Code and Gray Code (n = 3):
Synopsys University Courseware – ECE 240Lecture Set 2 – 38
Binary Code to Gray Code Conversion Convert n bit Binary code into n bit Gray Code:
Bit i of the Gray Code is obtained by comparing
bits i and i+1 of the Binary Code: Add extra 0 to the left of the Binary code
If bits i and i+1 in the Binary code are the same then bit i
of the Gray code is 0, else bit i is 1.
Example:
1001110011 010011010011BinaryBinary GrayGray11 11 0011 00
Synopsys University Courseware – ECE 240Lecture Set 2 – 39
Exercise
1110111101 011101011101BinaryBinary 1 0 0 1 11 0 0 1 1 GrayGray
i and i+1:i and i+1: same same 0 0;; else, else, 11
1 0 0 1 11 0 0 1 1 0 1 1 1 0 10 1 1 1 0 1GrayGray BinaryBinary
Synopsys University Courseware – ECE 240Lecture Set 2 – 40
Codes for Nondata Objects
n objects encoded with b=log2n=log10n/log102 binary bits.
Example: 124 objects, b=7
Application: The control unit runs one device at a time.
ControControl Unitl Unit
Enable?Enable?
DEVICEDEVICE
Enable?Enable?
DEVICEDEVICE
Enable?Enable?
DEVICEDEVICE
Binary-coded device selectBinary-coded device select
Synopsys University Courseware – ECE 240Lecture Set 2 – 41
Coding for Error Control
Bit error occurs due to noise, etc., if
0 sent is received as 1 or
1 sent is received as 0
EDC (error detecting codes) to detect bit errors
ECC (error correcting codes) to correct bit errors
Synopsys University Courseware – ECE 240Lecture Set 2 – 42
Detects any one bit error in a 2-bit block, but will miss two
11001111001100111100
10000011011000001101
To send:To send: 1011010110
send:send:
If we receiveIf we receive
we detect two errors but miss onewe detect two errors but miss one
EDC: Repetition-2 Code
Synopsys University Courseware – ECE 240Lecture Set 2 – 43
ECC: Repetition-3 Code
111000111111000111000111111000
110000100001001110000100001001
To send:To send: 1011010110
send:send:
If we receiveIf we receive
we correct two and miss two.we correct two and miss two.
Detects any one bit error in a 3-bit block, but will miss any two or three
Synopsys University Courseware – ECE 240Lecture Set 2 – 44
Parity-bit EDCs
To sendTo send mm bits,bits, bb11, b, b22, …, b, …, bmm..
SendSend m+1m+1 bits,bits, bb11, b, b22, …, b, …, bmm,,
pp,, wherewhere pp = = bb1 1 b b2 2 … … b bmm
(b(b11 b b2 2 … … b bm m pp = = 00))
SenderSender ReceiverReceiver
bb11, b, b22, …, b, …, bmm,, pp
When When rr11, r, r22, …, r, …, rmm, r, rm+1m+1 is received is received
computecompute s = s = rr11 r r2 2 … … r rm m r rm+1m+1
if if s=1s=1, then , then 11 (or 3 or 5 or …) (or 3 or 5 or …) bit errors occurred.bit errors occurred.
ifif s=0s=0,, then then 00 (or 2 or 4 or …) (or 2 or 4 or …) bit errors occurred, no error.bit errors occurred, no error.
P(2 or 4 or … errors)=P(2 or 4 or … errors)=P (undetected P (undetected
errors)errors)small enough for independent bit small enough for independent bit errorserrors
Synopsys University Courseware – ECE 240Lecture Set 2 – 45
Error-Detection
Error detection: use a dictionary of code words that is a subset of the 2n possible code words
A failure occurs when an invalid code word is sent
Synopsys University Courseware – ECE 240Lecture Set 2 – 46
Summary
Binary forms used in digital systems Positive/Negative numbers, addition/subtraction Arithmetic operations performed directly on negative numbers
represented in Two’s complement.
Hexadecimal numbers are used for shorthand representation of binary numbers.
Decimal numbers, characters, and actions encoded into binary strings.
Error-detecting and error-correcting codes use extra bits.