DLD Lecture 1 - (Digital Systems & Binary Numbers)
DLD Lecture 1 - (Digital Systems & Binary Numbers)
+5 +5
1 0 1
V V
Time Time
–5 –5
Digital: Analog:
only assumes discrete values values vary over a broad range
continuously
Digital Systems …continued 2 6
Signal examples over time
Time
Continuous in
Analog value & time
Digital
Discrete in
Asynchronous
value &
continuous in
time
Synchronous Discrete in
with the clock value & time
Digital Systems …continued 3
Advantages: 7
Cheap electronic circuitry
Easier to calibrate and adjust
Immunity to noise
Noise margin
Noise added
Sender Receiver
Signal Signal
3 23=8 11 211=2048
4 24=16 12 212=4096
5 25=32 20 220=1M Mega
Quinary System
Base (Radix): “5”
Symbols: 0, 1, 2, 3, 4
Weightage of each number increases by a factor of
“5” as its placement moves to the left
Example:
(4021.2)5 (Don’t call it four thousand and twenty one,
but four, zero, two, one, point two)
Base-8 Systems 19
Octal System
Base (Radix): “8”
Symbols: 0, 1, 2, … 6, 7
Weightage of each number increases by a factor of
“8” as its placement moves to the left
Example:
(127.4)8(Don’t call it one twenty seven point four, but
one, two, seven, point four)
Base-16 Systems 20
Hexadecimal System
Base (Radix): “16”
Symbols: 0, 1, 2, … 8, 9, A, B, C, D, E, F
Weightage of each number increases by a factor of “16” as
its placement moves to the left
Example:
(B65F)16
0.625 x 16 = A: a-1 = A
0.0x 16 = 0.0: a-2 = 0
(0.A0)16
Conversion between Number Systems 23
…continued 3
(48.5625)10 = (110000.1001)2
Conversion between Number Systems
…continued 5
25
Conversion to quinary number system:
(48.5625)10 = (?)5
(48.5625)10 = (143.2401)5
Conversion between Number Systems 26
…continued 6
(48.5625)10 = (60.44)8
Conversion between Number Systems 27
…continued 7
(48.5625)10 = (30.90)16
Conversion between Number Systems
…continued 8
28
Evaluate
Magnitude Octal
(Base 8)
Evaluate
Magnitude
Decimal Binary
(Base 10) (Base 2)
Hexadecimal
Evaluate (Base 16)
Magnitude
Conversion between Number Systems 30
…continued 9
2138
10001011
8 B16
Decimal, Binary, Octal and Hexadecimal 33
Decimal Binary Octal Hex
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Arithmetic 34
• Decimal Addition
1 1 Carry
5 5
+ 5 5
1 1 0
= Ten ≥ Base
Binary Arithmetic 35
Binary Addition
11 1 1
101101 ← augend
+1 0 0 1 1 1 ← addend
1010100
Binary Addition 36
• Column Addition
1 1 1 1 1 1
1 1 1 1 0 1 = 61
+ 1 0 1 1 1 = 23
1 0 1 0 1 0 0 = 84
≥ (2)10
Binary Arithmetic 37
…continued 2
Binary Subtraction
101101 ← minuend
−1 0 0 1 1 1 ← subtrahend
000110
Binary Subtraction 38
• Borrow a “Base” when needed
1 2 = (10)2
0 2 2 0 0 2
1 0 0 1 1 0 1 = 77
− 1 0 1 1 1 = 23
0 1 1 0 1 1 0 = 54
Binary Arithmetic 39
…continued 3
Binary Multiplication
1011 ← multiplicand
× 101 ← multiplier
1011
0000
1 0 1 1_____
110111
Binary Multiplication 40
• Bit by bit
1 0 1 1 1
x 1 0 1 0
0 0 0 0 0
1 0 1 1 1
0 0 0 0 0
1 0 1 1 1
1 1 1 0 0 1 1 0
Binary Arithmetic 41
…continued 4
Binary Division
Dividend Divisor
↓ ↓
1000001/1100=?
101 . ← Quotient
1100/1000001
1100↓↓ ← shift, if divisor is bigger and write 1 in quotient
010001 ← subtraction
1100 ← since brought down two bits write 01 in quotient
0101 ← Remainder
Complements of Numbers 42
r n − N ; N 0
0; N = 0
Examples: for a six digit decimal number (i.e. n=6)
10’s complement of 012398 = (106) – 012398 = 1000000 – 012398 = 987602
10’s complement of 246700 = (106) – 246700 = 1000000 – 246700 = 753300
However, r’s complement is (r-1)’s complement + 1
Obtaining (r-1)’s complement is easy
each digit is subtracted from 9
= 753299 + 1 = 753300
Complements of Numbers
…continued 4
45
For binary numbers:
r = 2 and
2’s complement is obtained by adding 1 to 1’s complement
Example: 7 digits number (n=7)
2’s complement of 1101100 = 0010011 + 1
= 0010100
2’s complement of 0110111 = 1001000 + 1
= 1001001
i.e. The 2’s complement is obtained by leaving the least significant 0’s and the first
1 unchanged and then replacing 1’s with 0’s and 0’s with 1’s
M–N=?
1. Add the minuend “M” to the r’s complement of subtrahend
“N”
➢ M + (rn – N) = M – N + rn
2. If M ≥ N, the sum will produce an end carry and will be
discarded
3. If M < N, then there will be no end carry in the sum and the
sum will be
➢ rn – (N – M), which is r’s complement of (N – M)
➢ So, take the r’s complement of the sum and place negative sign in front
Subtraction with Complements
…continued 2 47
Examples:
1. 72532 – 3250 = ? (M ≥ N)
M = 72532
10’s complement of N = + 96750
169282
Discard the end carry M – N = 69282
M= 1010100
2’s complement of N = +0111101
10010001
Discard the end carry M – N = 1 0 0 0 1
M = 1000011
1’s complement of N = + 0 1 0 1 0 1 1
1101110
No end carry, so take
(r – 1) ‘s complement of the sum = 0 0 1 0 0 0 1 and
place negative sign
M–N=–10001
Signed Binary Numbers
Positive integers (0, 1, 2, . . . ) can be represented as
51
unsigned numbers
For negative numbers in ordinary arithmetic, we use minus
sign
However, Computer hardware has to represent everything in
bits
So, the left most bit is used to represent the sign
It is important that representation is known in advance
Unsigned
(01001)2 = (9)10 (11001)2 = (25)10
Signed:
(01001)2 = (9)10 (11001)2 = (– 9 )10
Signed magnitude convention: i.e. magnitude and the symbol (+ or –) or (0 or 1)
Signed Binary Numbers
…continued 2
Signed magnitude convention is the one used in ordinary arithmetic52
However, in computers, arithmetic operations are implemented using
signed complement system
Magnitude of
Convenient
9
Signed 1’s complement (relatively difficult)
Signed 2’s complement (Easier, more common) 1’s
(– 9)10 represented in three systems (using 8 bits) complement
of 9
Signed magnitude representation: 10001001
Signed 1’s complement representation: 11110110 2’s
complement
Signed 2’s complement representation: 11110111 of 9
In all three systems
Sign bit:
Left most bit represents (positive or negative sign) representing
The remaining part represents magnitude or complement –ve number
Signed Binary Numbers…continued 3
53
4-bits (Left most for sign and 3 bits for magnitude or complement)
0–7
Supplementary Reading:
http://ecse.bd.psu.ed
u/cse271/twoscomp.
pdf
Signed Binary Numbers…continued 4
Arithmetic addition
54
Ordinary arithmetic (sign magnitude system) requires comparison of
signs and magnitudes
Signed complement system does not require comparison or
subtraction
• Example: A
binary code Color Binary Number
Red 000
for the seven Orange 001
colors of the Yellow 010
rainbow Green 011
• Code 100 is Blue 101
not used Indigo 110
Violet 111
8 1000
+ 9 1001
17 1 0 0 0 1 end carry
0 1 1 0 for correction add 6
10111
= (0001 0111)BCD
Other Decimal Codes
63
• Wighted Codes:
• Each bit has associated weightage
• e.g.
• BCD (8421)
• 2421 Codes:
• Left most bit has weightage of 2
• Right most bit has wieghtage of 1
• Self complementing Codes:
• 9’s complement of the decimal code is directly obtained by
changing 1s to 0s and 0s to 1s
• e.g.
• 2421 Codes
• Excess-3
• Binary value + 3
ALPHANUMERIC CODES - ASCII Character
Codes 64
• American Standard Code for Information
Interchange
• This code is a popular code used to represent
information sent as character-based data. It
uses 7-bits to represent:
– 94 Graphic printing characters.
– 34 Non-printing characters
• Some non-printing characters are used for text
format (e.g. BS = Backspace, CR = carriage
return)
ASCII Code: B7B6B5 B4B3B2B1
65
H=(1001000)
PARITY BIT Error-Detection Codes
66
• Redundancy (e.g. extra information), in the form of extra
bits, can be incorporated into binary code words to detect
and correct errors.
• A simple form of redundancy is parity, an extra bit
appended onto the code word in the most significant position
to make the number of 1’s odd or even. Parity can detect all
single-bit errors and some multiple-bit errors.
7
TX RX
At the receiver side:
If an even parity is
Parity bit
detected, send an ACK
Transmit Ha in ascii: control = 00000110
1001000 1100001 If error was detected
Transmit with even parity:
send negative
01001000 11100001 acknowledge NAK =
10010101
Binary Gray
000 000
001 2 bit changes 001
010 011
011 2 bit changes 010 Only 1 bit changes
100 110
101 2 bit changes 111
110 101
111 100
As we “count” up or down in decimal, the code word
for the Gray code changes in only one bit position as
we go from decimal digit to digit including from 9 to 0.
Binary Storage and Registers
69
Register:
0000
Device for holding data 0001
0010
Most common device for holding data 0011
0100
Array of binary cells 0101
Cell is capable of storing a bit (0, 1) information 0110
0111
Can be set to one of two states 1000
1001
An “n” cell register can be one of 2n states 1010
0 → 2n – 1 1011
1100
Example: n=4 1101
1110
1111
Binary Storage and Registers
…continued 2 70
Register Transfer
register transfer operation is
a basic operation that
consists of a transfer of
binary information from
one set of registers into
another set of registers.
Binary Storage and Registers …continued 3
71
Example of binary
information processing
Binary Logic
72
Deals with variable that can take on two discrete values
1, 0
True, False
Yes, No
Variables are designated as
A, B, C, x, y, z, etc.
Binary logic or Boolean algebra has three basic logical
operations
AND
OR
NOT
Binary Logic …continued 2
73
AND operation:
Represented by dot “∙” operator or absence of operator
Read as “x AND y = z”
x ∙ y = z; (x, y, z are binary variables)
Truth table
x y z=x.y
0 0 0
0 1 0
1 0 0
1 1 1
z = 1; iff x = 1 and y = 1
Symbol
Binary Logic …continued 3
74
OR operation:
Represented by plus “+” operator
Read as “x OR y = z”
x + y = z; (x, y, z are binary variables)
Truth table
x y z=x+y
0 0 0
0 1 1
1 0 1
1 1 1
Read as “NOT x = z”
X’ = z; (x, z are binary variables)
Truth table x z = x’
0 1
1 0
AND OR
Recommended Reading 79
http://www.mathsisfun.com/binary-number-
system.html
http://en.wikipedia.org/wiki/Binary_number
http://www.basic-mathematics.com/base-
five.html
http://www.facstaff.bucknell.edu/mastascu/elessonshtml/Log
ic/Logic1.html
http://ecse.bd.psu.edu/cse271/twoscomp.pdf
http://www.williamson-labs.com/480_logic.htm