Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 79

Electrical

Engineering

Islamabad

EEE241
Digital Logic Design
Lecture No. 1
Dr. Riaz Hussain
Assistant Professor
Department of Electrical Engineering
COMSATS Institute of Information Technology, Islamabad
Review
• Introduction to course and course material
• Why DLD?
• What is DLD?
– Abstraction
– Divide and conquer
– Build upon previous work
• Digital Systems
– Advantages

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 2


Outline
• Digital Systems
• Binary Numbers
• Number-Base Conversions
• Octal and Hexadecimal Numbers
• Complements of Numbers
• Subtraction with complements
• Signed Binary Numbers
• Binary Codes
• Binary Storage and Registers
• Binary Logic

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 3


Must Reading
• Chapter No. 1: Digital Systems and Binary
Numbers

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 4


Digital Systems
• Digital Vs. Analog

+5 +5

1 0 1
V V
Time Time

–5 –5

Digital: Analog:
only assumes discrete values values vary over a broad range
continuously

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 5


Digital Systems …continued 2
• 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
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 6
Digital Systems …continued 3
• Advantages:
– Cheap electronic circuitry
– Easier to calibrate and adjust
– Immunity to noise
• Noise margin Noise added

Sender Receiver

Signal Signal

 Thus digital systems have


captured the market
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 7
Digital Systems
• Discrete Data
– Examples:
• 26 letters of the alphabet (A, B … etc.)
• 10 decimal digits (0, 1, 2 … etc.) Analog Discrete

– Combine together
• Words are made of letters (University … etc.)
• Numbers are made of digits (4241 … etc.)
• Binary System
– Only ‘0’ and ‘1’ digits
– Can be easily implemented in electronic circuits

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 8


Decimal Number System
• Base (also called radix) = 10
– 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
• Digit Position 2 1 0 -1 -2

– Integer & fraction


• Digit Weight 100 10 1 0.1 0.01
– Weight = (Base) Position
• Magnitude
500 10 2 0.7 0.04
– Sum of “Digit x Weight”
d2*B2+d1*B1+d0*B0+d-1*B-1+d-2*B-2
• Formal Notation
(512.74)10
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 9
Binary Systems
• Review, how the decimal system is designed?
– Base (Radix) 10
– Symbols: 0, 1, 2, … 8, 9
– What if quantity greater than 9?
• Add more significant digits to the left
– Each position carries a weight
• Example: 7392
• 7 × 103 + 3 × 102 + 9 × 101 + 2 × 100 = 7392
• Seven thousand three hundred and ninety two
• Weightage increases as the digit placement moves to left
and vice versa
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 10
Binary Systems …continued 2
– What if weightage is less than 100
• We use the symbol point (.) and write the number to the
right
• MSD →103 102 101 100 . 10-1 10-2 ← LSD
– Base-10 is default base for numbering system
– But, we can generalize the rule for any base-r
system from the base-10 (decimal) number system
• Base (Radix) is “r”
• Symbols: 0 → (r – 1)
• Weightage of each number increases by a factor of “r”
as its placement moves to the left
r3 r2 r1 r0 . r-1 r-2

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 11


Binary Systems …continued 3
– Example: an…a5a4a3a2a1a0.a-1a-2a-3…a-m
an × rn +…a5 × r5 + a4 × r4 + a3 × r3 + a2 × r2 + a1 × r1 + a0 ×
r0 + a-1 × r-1 + a-2 × r-2 + a-3 × r-3 + … a-m × r-m
– Simplified:
• aj = {0 → (r – 1)}
• j is the location of digit “aj” of the quantity in decimal
numbers is: n
D a
j  m
j
j r

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 12


Binary Systems …continued 4

• As we know the general rule, now we can


understand how the binary (base-2) would work
– Base (Radix): “2”
– Symbols: 0, 1
– Weightage of each number increases by a factor of
“2” as its placement moves to the left
• Example:
• (11010)2 (Don’t call it eleven thousand and ten, but
one,one,zero,one,zero; we are not in decimal system)
• (11010.11)2

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 13


Special Powers of 2
210 (=1024) is Kilo, denoted "K"

220 (=1,048,576) is Mega, denoted "M"

230 (1,073, 741,824) is ? Giga, denoted "G"


240 (1,099,511,627,776 ) is Tera, denoted “T"
• Note: 8 bits (b) are also called a byte (B)
Exercise: what is (1111 1111)2 equal to in decimal?
Also what is the maximum number (in decimal) a two bytes long word can represent?

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 14


Range of Binary Numbers
• Binary number: ex. a 3-bit number: n=3
– 000, 001 … ,111 or in decimal system: 0, 1 … 7
• Total of 8 numbers (=23)
• Range: from 0 to 7 (0 to 23-1)
– In general an n-bit number represents:
• 2n different numbers
• Min: 0
• Max number: 2n-1
• For fractions: m bits after the radix point:
– Min: 0
– Max number: (2m -1)/2m

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD Lecture-01 15


The Power of 2
n 2n n 2n
0 20=1 8 28=256
1 21=2 9 29=512
2 22=4 10 210=1024 Kilo

3 23=8 11 211=2048
4 24=16 12 212=4096
5 25=32 20 220=1M Mega

6 26=64 30 230=1G Giga

7 27=128 40 240=1T Tera


Examples of Binary Numbers
• 16 Gbyte (= 16 GB) of memory
– How many (address) bits are required to
address each byte?
• Digital camera has 2048x2048 pixels, and
each pixel stores 8 bits of information:
a. How many Mega pixels?
b. How many bits are stored per frame?
c. How many different intensity levels can be represented by each pixel?

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 17


Base-5 Systems
• 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)

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 18


Base-8 Systems
• 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)

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 19


Base-16 Systems
• 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
• Hexadecimal numbers are used to represent
long strings of bits in addresses, instructions
and data
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 20
Conversion between Number Systems
• Conversion of decimal integer
– Repeated division
– Examples:
• 57
– Binary
– Quinary
– Octal
– Hexadecimal
57/2 = 28: rem= 1=a0 57/5=11: rem=2 57/8=7: rem=1
28/2 = 14: rem= 0=a1 11/5 = 2: rem=1 (71)8
14/2 = 7: rem= 0=a2 (212)5
7/2 = 3: rem= 1=a3 57/16=3: rem=9
3/2 = 1: rem= 1=a4 (39)16
1/2 = 0: rem= 1=a5
(111001)2
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 21
Conversion between Number Systems
…continued 2
• Conversion of decimal fraction
0.625 x 2 = 1.250: a-1 = 1
– Repeated multiplication 0.250 x 2 = 0.50: a-2 = 0
– Examples: 0.500 x 2 = 1.0: a-3 = 1
(0.101)2
• 0.625 0.625 x 5 = 3.125: a-1 = 3
– Binary 0.125 x 5 = 0.625: a-2 = 0
– Quinary 0.625 x 5 = 3.125: a-3 = 3
– Octal (0.303)5
– Hexadecimal 0.625 x 8 = 5.0: a-1 = 5
0.0x 8 = 0.0: a-2 = 0
(0.50)8
0.625 x 16 = A: a-1 = A
0.0x 16 = 0.0: a-2 = 0
(0.A0)16
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 22
Conversion between Number Systems
…continued 3
• Conversion of mixed decimal numbers
– Convert the integer part using repeated division
– Covert the fraction part using repeated
multiplication
– Combine the integer and fractional components in
the new base
– Example:
• (48.5625)10

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 23


Conversion between Number Systems
…continued 4
– Conversion to binary number system:
• (48.5625)10 = (?)2
• Repeated division Repeated multiplication
48/2 = 24: a0 = 0 0.5625 x 2 = 1.1250: a-1 = 1
24/2 = 12: a1 = 0 0.1250 x 2 = 0.2500: a-2 = 0
12/2 = 6: a2 = 0 0.2500 x 2 = 0.5000: a-3 = 0
6/2 = 3: a3 = 0 0.5000 x 2 = 1.0000: a-3 = 1
3/2 = 1: a4 = 1 (0.1001)2
1/2 = 0: a5 = 1
(110000)2

• (48.5625)10 = (110000.1001)2

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 24


Conversion between Number Systems
…continued 5
– Conversion to quinary number system:
• (48.5625)10 = (?)5
• Repeated division Repeated multiplication
48/5 = 9: a0 = 3 0.5625 x 5 = 2.8125: a-1 = 2
9/5 = 1: a1 = 4 0.8125 x 5 = 4.0625: a-2 = 4
1/5 = 0: a2 = 1 0.0625 x 5 = 0.3125: a-3 = 0
(143)5 0.3125 x 2 = 1.5625: a-4 = 1
(0.2401)5

• (48.5625)10 = (143.2401)5

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 25


Conversion between Number Systems
…continued 6
– Conversion to octal number system:
• (48.5625)10 = (?)8
• Repeated division Repeated multiplication
48/8 = 6: a0 = 0 0.5625 x 8 = 4.5000: a-1 = 4
6/8 = 0: a1 = 6 0.5000 x 8 = 4.0000: a-2 = 4
(60)8 0.0000 x 8 = 0.0000: a-3 = 0
(0.440)8

• (48.5625)10 = (60.44)8

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 26


Conversion between Number Systems
…continued 7
– Conversion to hexadecimal number system:
• (48.5625)10 = (?)16
• Repeated division Repeated multiplication
48/16 = 3: a0 = 0 0.5625 x 16 = 9.000: a-1 = 9
3/16 = 0: a1 = 3 0.0000 x 16 = 0.000: a-2 = 0
(30)16 (0.90)16

• (48.5625)10 = (30.90)16

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 27


Conversion between Number Systems
…continued 8
– Conversion from base-A to base-B can be carried
out by repeated division and repeated
multiplication
• Make sure you do the division and multiplication using
the correct base
• Base-A → Base-B
– It is easier (generally) to covert base-A to base-10
and then to base-B
• Base-A → Base-10 → Base-B

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 28


Number Base Conversions
Evaluate
Magnitude
Octal
(Base 8)

Evaluate
Magnitude
Decimal Binary
(Base 10) (Base 2)

Hexadecimal
(Base 16)
Evaluate
Magnitude
Conversion between Number Systems
…continued 9
– Conversion between binary and octal
• Each octal digit corresponds to three (3) bits
• Examples:
– (101 110 010 . 011 001 )2 = (562.31)8
– (010 011 100 . 101 001 )2 = (234.51)8
– (745.32)8 = (111 100 101 . 011 010)2
– (306.05)8 = (011 000 110 . 000 101)2

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 30


Conversion between Number Systems
…continued 10
– Conversion between binary and hexadecimal
• Each hexadecimal digit corresponds to three (4) bits
• Examples:
– (1001 1010 0110 . 1011 0101 )2 = (9A6.B5)16
– (1100 1011 1000 . 1110 0111 )2 = (CB8.E7)16
– (E94.D2)16 = (1110 1001 0100 . 1101 0010)2
– (1C7.8F)16 = (0001 1100 0111 . 1000 1111)2

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 31


Conversion between Number Systems
…continued 11
– Conversion octal to hexadecimal and vice versa
using binary
• Convert 2138 into an hexadecimal number:

2138

10001011
8 B16

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 32


Decimal, Binary, Octal and
Decimal Hexadecimal
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
• Decimal Addition

1 1 Carry
5 5
+ 5 5

1 1 0
= Ten ≥ Base
Binary Arithmetic
– Binary Addition
1 1 1 1

101101 ← augend
+100111 ← addend
1010100

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 35


Binary Addition
• 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 …continued 2
– Binary Subtraction

101101 ← minuend
−100111 ← subtrahend
000110

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 37


Binary Subtraction
• 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 …continued 3
– Binary Multiplication

1011 ← multiplicand
× 101 ← multiplier
1011
0000
1011 =
110111

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 39


Binary Multiplication
• 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 …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

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 41


Complements of Numbers
Complements are used to simplify subtraction operation
• Diminished Radix Complement
– Given an “n” digits number “N” in base “r” the (r-1) complement is:
– (rn – 1) – N
– Examples:
9’s complement of 546700 = (106 – 1) – 546700 =
999999 – 546700
= 453299
9’s complement of 012398 = (106 – 1) – 012398 =
999999 – 012398
= 987601

i.e. each digit is subtracted from 9


02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 42
Complements of Numbers
…continued 2
– For binary numbers:
• r = 2 and (r – 1) = 1
• For “n” = 4
– 24 = (10000)2
– 24 – 1 = (1111)2
– So, 1’s complement is
• 24 – 1 – N = 1111 – N
i.e. each digit is subtracted from 1
– However:
• 1–1=0 and 1–0=1
– So, 1’s complement of binary numbers are formed by changing
1’s to 0’s and 0’s to 1’s
• Examples:
– 1’s complement of 1011000 = 0100111
– 1’s complement of 0101101 = 1010010
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 43
Complements of Numbers
…continued 3
• Radix Complement
– Given an “n” digits number “N” in base “r” the “r’s” complement is:
n
r  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
10’s complement of 012398 = (999999 – 012398) + 1
= 987601 + 1 = 987602
10’s complement of 246700 = (999999 – 246700) + 1
= 753299 + 1 = 753300
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 44
Complements of Numbers
…continued 4
– 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

“Complement of the complement restores the number”


(rn – 1) – [(rn – 1) – N] = N
rn – [rn – N] = N
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 45
Subtraction with Complements
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

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 46


Subtraction with Complements
Examples: …continued 2
1. 72532 – 3250 = ? (M ≥ N)
M = 72532
10’s complement of N = + 96750
169282
Discard the end carry M – N = 69282

2. 3250 – 72532 = ? (M < N)


M = 03250
10’s complement of N = + 27468
30718
No end carry, so take
r‘s complement of the sum = 69282
and place negative sign
M – N = – 69282
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 47
Subtraction with Complements
…continued 3
Examples for binary numbers (same principle):
1. 1010100 – 1000011= ? (M ≥ N)

M= 1010100
2’s complement of N = + 0 1 1 1 1 0 1
10010001
Discard the end carry M – N = 1 0 0 0 1

2. 1000011 – 1010100 = ? (M < N)


M = 1000011
2’s complement of N = + 0 1 0 1 1 0 0
1101111
No end carry, so take
r‘s complement of the sum = 0 0 1 0 0 0 1 and place
negative sign
M–N=–10001
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 48
Subtraction with Complements
…continued 4
Subtraction of unsigned numbers can also be
done using (r – 1)’s complement
(r – 1)’s complement is 1 less than r’s complement,
So, the sum of minuend and the complement of subtrahend is
1 less than correct difference, when an end carry occurs
So, to get the correct difference remove the carry and add 1,
i.e. end around carry
1. 1010100 – 1000011= ? M = 1010100
An example of (M ≥ N) 1’s complement of N =+0111100
10010000
If carry, end around carry
0010000
+ 1
Discard the end carry M – N = 0 0 1 0 0 0 1

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 49


Subtraction with Complements
…continued 5
Subtraction of unsigned numbers can also be
done using (r – 1)’s complement
When the sum of minuend and (r – 1)’s complement has no end
carry then take (r – 1)’s complement of the sum and place
minus sign
1. 1000011 – 1010100 = ?
An example of (M < N)
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

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 50


Signed Binary Numbers
• Positive integers (0, 1, 2, . . . ) can be represented as
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)
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 51
Signed Binary Numbers…continued 2
• Signed magnitude convention is the one used in ordinary
arithmetic
• 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
complement
• (– 9)10 represented in three systems (using 8 bits)
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
– Left most bit represents (positive or negative sign) Sign bit:
representing
– The remaining part represents magnitude or complement –ve number
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 52
Signed Binary Numbers…continued 3
• 4-bits (Left most for sign and 3 bits for magnitude or complement)
• 0–7

Positive numbers have


same representation in
all three systems

Left most bit (i.e. Most


significant bit) represents
{
sign in all three systems

Supplementary Reading:
http://ecse.bd.psu.edu/c
se271/twoscomp.pdf
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 53
Signed Binary Numbers…continued 4
• Arithmetic addition
– Ordinary arithmetic (sign magnitude system) requires comparison of
signs and magnitudes
– Signed complement system does not require comparison or
subtraction

The addition of two signed binary numbers with negative


numbers represented in signed‐ 2’s‐complement form is
obtained from the addition of the two numbers, including
their sign bits. A carry out of the sign‐bit position is
discarded.

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 54


Signed Binary Numbers…continued 5
• Arithmetic addition using signed-2’s complement
– Negative numbers must be in the form of signed-2’s complement
– The result is also obtained in the signed-2’s complement form
+ 6 0000 0110 – 6 1111 1010
+ 13 0000 1101 + 13 0000 1101
+19 0001 0011 + 7 10000 0111
Carry discarded
+ 6 0000 0110 Ans: 0000 0111
– 13 1111 0011
– 7 1111 1001 – 6 1111 1010
– 13 1111 0011
– 19 11110 1101
Carry discarded
Ans: 1110 1101

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 55


Signed Binary Numbers…continued 6
• Arithmetic addition
– Buffer overflow
Overflow is a problem in computers because the number of bits
that hold a number is finite, and a result that exceeds the finite
value by 1 cannot be accommodated.
– If we start with two n‐bit numbers and the sum occupies n + 1 bits, we
say that an overflow has occurred
– Example: (4 bit signed number addition using signed-2’s-complement)

+ 4 0100
+ 5 0101
+ 9 1001
BUT, 1 0 0 1 is the representation of – 7 and not 9
• In order to obtain a correct answer, we must ensure that the result has a
sufficient number of bits to accommodate the sum.

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 56


Signed Binary Numbers…continued 6
• Arithmetic subtraction using signed-2’s complement
Take the 2’s complement of the subtrahend (including the
sign bit) and add it to the minuend (including the sign bit). A
carry out of the sign‐bit position is discarded.
( A)  ( B)  ( A)  ( B);
( A)  ( B)  ( A)  ( B);
– i.e. we, change the subtraction operation to addition and
– Subtrahend positive number is changed to negative and negative to
positive by taking the 2’s complement
– Example: (–6) – (–13) = (–6) + (+13) – 6 1111 1010
+ 13 0000 1101
+ 7 10000 0111
Carry discarded
Ans: 0000 0111

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 57


Signed Binary Numbers…continued 7
Why Signed-Complement System?
It is worth noting that binary numbers in the signed‐complement
system are added and subtracted by the same basic addition
and subtraction rules as unsigned numbers. Therefore,
computers need only one common hardware circuit to
handle both types of arithmetic.

Why Signed-2’s Complement is preferred over signed-1’s


complement?
Please read the article on http://ecse.bd.psu.edu/cse271/twoscomp.pdf
and answer in next class.

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 58


Binary Codes
• An n-bit binary code is an n-bit word which
can represent up to 2n different elements.
• Example: 3-bit code can represent up to 8
different elements”

All quantities in a PC needs to be expressed as a binary


number: e.g. the digits 0, 1, …9; characters, control
characters, etc. This can be done using a “Code

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 59


Binary Codes
• 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

• 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 or elements.

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 60


Binary Coded Decimal (BCD)

• The BCD code is the 8,4,2,1 code.


• This code only encodes the first ten
values from 0 to 9.
• Each decimal digit is coded separately by
4 bits
• Example:
– (325)10 = (0011 0010 0101)BCD
3 2 5

• Exercise: (856)10 = ( )BCD


Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01
Binary Coded Decimal (BCD)
…continued 2
4 0100
+ 5 0101
• BCD Addition: 9 1001
4 0100
+ 8 1000
12 1 1 0 0 not a valid BCD number
0 1 1 0 for correction add 6
10010
= (0001 0010)BCD

8 1000
+ 9 1001
17 1 0 0 0 1 end carry
0 1 1 0 for correction add 6
10111
= (0001 0111)BCD

Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01


Other Decimal Codes
• 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

Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01


ALPHANUMERIC CODES - ASCII Character
Codes

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

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 64


ASCII Code: B7B6B5 B4B3B2B1
H=(1001000)

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 65


PARITY BIT Error-Detection Codes
• 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.

A code word has even parity if the


number of 1’s in the code word is even. 7
A code word has odd parity if the TX RX
number of 1’s in the code word is odd. Parity bit

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 66


ASCII Parity Code Example

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

added parity bit

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 67


GRAY CODE – Decimal

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.
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 68
Binary Storage and Registers
• Register: 0000
– Device for holding data 0001
0010
– Most common device for holding data 0011
– Array of binary cells 0100
• Cell is capable of storing a bit (0, 1) information 0101
• Can be set to one of two states 0110
0111
– An “n” cell register can be one of 2n states 1000
• 0 → 2n – 1 1001
1010
– Example: n = 4
1011
1100
1101
1110
1111

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 69


…continued 2
Binary Storage and Registers
• 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.

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 70


…continued 3
Binary Storage and Registers
• Example of binary
information processing

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 71


Binary Logic
• 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

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 72


…continued 2
Binary Logic
• 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

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 73


…continued 3
Binary Logic
• 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
– z = 1; if x = 1 or y = 1 or if both x=1 and y=1
– Symbol

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 74


…continued 4
Binary Logic
• NOT operation:
– Represented by prime “’” operator or overbar operator
• x’ = z
• x=z
– Read as “NOT x = z”
– X’ = z; (x, z are binary variables)
– Truth table

x z = x’
0 1
1 0

– Also called complement


– z is what x is not
– Symbol
02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 75
…continued 5
Binary Logic
• Binary logic should not be confused with binary arithmetic
• Operators used are also identical
– Dot “.” for multiplication and also for AND
– Plus “+” for addition and also for OR
– Prime “’” for complement and also for NOT
Arithmetic variables designates number that may consist of many digits,
whereas,
Logical variable is always 1 or 0

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 76


…continued 5
Binary Logic
• Logic Gates:
– Electronic circuits operating on one or more input signals to produce
an output signal

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 77


Switching Circuits
AND OR
Recommended Reading
• 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/Logic/Logic1.htm
l
• http://ecse.bd.psu.edu/cse271/twoscomp.pdf
• http://www.williamson-labs.com/480_logic.htm

02/23/2024 Riaz Hussain (rhussain@comsats.edu.pk) CIIT-IBD-EE EEE241 DLD BCE-3 Lecture-01 79

You might also like