0% found this document useful (0 votes)
13 views80 pages

DLD 1

This document discusses digital systems and binary numbers, explaining how digital data is represented using binary codes and the significance of binary digits (bits). It covers conversions between different number bases, including binary, decimal, octal, and hexadecimal, and provides examples of arithmetic operations and base conversions. The document emphasizes the efficiency of digital systems in processing discrete information compared to analog systems.
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)
13 views80 pages

DLD 1

This document discusses digital systems and binary numbers, explaining how digital data is represented using binary codes and the significance of binary digits (bits). It covers conversions between different number bases, including binary, decimal, octal, and hexadecimal, and provides examples of arithmetic operations and base conversions. The document emphasizes the efficiency of digital systems in processing discrete information compared to analog systems.
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/ 80

1

CHAPTER 1
DIGITAL SYSTEMS
AND BINARY
NUMBERS
This chapter presents the various binary systems
suitable for representing information in digital
systems. The binary number system is explained
and binary codes are illustrated.

* Slide numbers are given to facilitate you to note points.


2

1.1 Digital Systems


• Digital systems are those which process and utilize digital
data to make daily routine work easier.
• Digital data represents a large set of discrete elements
such as alphabets, playing cards, and 64 squares of a
chessboard.
• Representing a set of discrete into digital makes the
processing easier and efficient since we have methods
and machines that can store and process digital data with
far more efficiency than analog systems.
• Early digital computers were used for numeric
computations and the discrete elements used were digits
hence the term “digital computer” emerged.
3

1.1 Digital Systems


• Using only two digits or levels of voltage for storing
signals is easier and thus this system is said to be binary.

• A binary digit, called a bit, has two values: 0 & 1,


physically represented by two voltage levels 0 V & 5 V (or
3.3 V)

• Discrete elements of information are represented with


group of bits called binary codes. e.g. digits 0 through 9
are represented by code of 4 bits (e.g. 7 ≡ 0111)

• Digital storages for storing data e.g. hard-disk, CD ROM,


DVD
4

1.2 Binary Numbers (Base r→10


conversion)
Th H T U
7 3 9 2 = 7000 + 300 + 90 + 2
= 7 x 1000 +3 x100 + 9 x10 + 2 x 1
= 7 x 103 + 3 x 102 + 9 x 101 + 2 x 100
With decimal point (or radix point)
125.42 = 100 + 20 + 5 + 0.4 + 0.02
= 1 x 100 + 2 x 10 + 5 x 1 + 4/10 + 2/100
= 1 x 102 + 2x 101 + 5 x 100 + 4 x 10-1 + 2 x 10-2
Generally, a5a4a3a2a1a0a-1a-2a-3
a5 x 105 + a4 x 104 + a3 x 103 + a2 x 102 + a1 x 101 + a0 x 100
+ a-1 x 10-1 + a-2 x 10-2 + a-3 x 10-3
From the position of coefficient ‘a’, one can easily determine
The power of 10. On the left side of “radix point” power of 10
increases and on the right side it decreases.
5

1.2 Binary Numbers (Base r→10 conversion)


• Decimal number system is said to be of base-10,
or radix-10 because coefficients are multiplied by the
powers of 10
• For representing the base of the system, we write
numbers as (7392)10
• The binary system has only two values i.e. 0 & 1. Thus,
the base is 2. Decimal equivalent of a binary is
(11011.11)2
= 1 x 24 + 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 + 1 x 2-1 + 1 x 2-2
= 16 + 8 + 0 x 4 + 2 + 1 + ½ + ¼
= 16 + 8 + 0 + 2 +1 + 0.5 + 0.25 = (27.75)10
6

1.2 Binary Numbers (Base r→10 conversion)


• In general a base-r number is expressed in decimal
(base-10) as:
an.rn+an-1.rn-1+…+a2.r2+a1.r1+a0.r0+ a-1.r-1+ a-2.r-2+…+ a-m.r-m

• Base-5: (4021.2)5 =4x53+0x52+2x51+1x50+2x5-1 =(511.4)10

• Base-8: (123.4)8 =1x82+2x81+3x80+4x8-1 =(83.5)10

• To distinguish between different bases, number is


enclosed in parenthesis and base is written as a
subscript. If there is no subscript written, base is assumed
to be 10 (decimal number system).
7

1.2 Binary Numbers


Base Digits
2 (Binary) 0,1
5 0,1,2,3,4
8 (Octal) 0,1,2,3,4,5,6,7
10 (Decimal) 0,1,2,3,4,5,6,7,8,9
16 (Hexadecimal) 0,1,2,3,4,5,6,7,8,9
A,B,C,D,E,F
Base-r (r<10) 0 to r-1 from decimal
Base-r (r>10) 0 to 9 from decimal,
Rest from Alphabet

(B44B)16 = 11 x 163 + 4x162 + 4 x 161 + 11 x 160 = (46,155)10


8

1.2 Binary Numbers


• Binary digits are referred to as bits. When a bit is 0, it
doesn’t contribute anything to the total. So, we can
neglect the powers of 2 where the bit is zero and can add
the powers where bit is ‘1’ in order to obtain decimal
equivalent. e.g. (110101)2= 25+24+.+22+.+20=32+16+4+1
Powers of 2
n 2n n 2n n 2n In computer work,
K (kilo) = 210
0 1 8 256 16 66,356
M (mega) = 220
1 2 9 512 17 131,072 G (giga) = 230
2 4 10 1024 18 262,144 T (tera) = 240
4 k = 22 x 210 = 212
3 8 11 2048 19 524,288 = 4,096
4 16 12 4096 20 1,048,576 16M = 24 x 220 = 224
5 32 13 8,192 21 2,097,152 = 16,777,216
4 GB = 22 x 230 =232
6 64 14 16,384 22 4,194,304 = 4 billion bytes
7 128 15 32,768 23 8,388,608 (approx.)
9

1.2 Binary Numbers


• Arithmetic operations with numbers in base-r follows
same rules except resulting digits can only range from 0
to r-1. Also, borrow in case of subtraction has to be ‘r’
• For binary addition, if result exceeds, we can carry ‘1’.
• For binary subtraction, if borrow needed, ‘2’ is borrowed.
• For binary multiplication, either add 0 or the whole
number.
1 1 1 1 101
101101 101101 X 1101
+10011 -10011
101
1
1 010100 1 +0000X
1
Subtract +1011XX
manually 110111
10

Message for end of every


lecture:
Solve end of chapter
problems (Keeping a
manual won’t be enough)
11

1.3 Number-Base Conversions


• To convert from base-r to decimal, we used to multiply the
coefficients of integer part with positive powers of r and
fraction with negative powers of r or rather divide with
increasing powers of r.

• Reversing the process gives us conversion from decimal


to base-r. Integer part is repeatedly divided by ‘r’ and
fraction part is multiplied by ‘r’.

• Let’s demonstrate by an example: (41)10=(?)2


• Here r=2 and the number is 41 and it’s only integer.
12

1.3 Number-Base Conversions


• Example 1.1: Convert decimal 41 to binary i.e. base 2
• (41)10=(?)2
Integer
Remainder Coefficient
Quotient
41 / 2 20 + ½ a0=1
20 / 2 10 + 0 a1=0
10 / 2 5 + 0 a2=0
5 /2 2 + ½ a3=1
2/2 1 + 0 a4=0
1/2 0 + ½ a5=1
13

1.3 Number-Base Conversions


• Convenient method? (41)10=(?)2

2 41
2 20 – 1 Divide until the
2 10 – 0 Quotient is less
than ‘r’. Here 2
2 5 – 0
2 2 – 1
2 1 – 0

LSB= Least Significant Bit

MSB= Most Significant Bit

• Now (41)10 = (101001)2


14

1.3 Number-Base Conversions


• Example 1.2: Convert decimal 153 to octal i.e. base 8

8 153
Divide until the
Quotient is less
than ‘r’

Perform operation manually

• Now (153)10 = (231)8


15

1.3 Number-Base Conversions


Multiply until get


‘0’ remainder
16

1.3 Number-Base Conversions


• Example 1.4: Convert (0.513)10 to octal i.e. base-8
• 0.513 x 8 = 4.104
• 0.104 x 8 = 0.832 Multiply until get
‘0’ remainder
• 0.832 x 8 = 6.656
OR
• 0.656 x 8 = 5.248 have accumulated
• 0.248 x 8 = 1.984 digits for enough
• 0.984 x 8 = 7.872 accuracy

• (0.513)10 = (0.406517…)8
• Convert (41.6875)10 to binary ?
• Convert 41 to binary and 0.6875 to binary and then
combine.
17

1.3 Number-Base Conversions


• Combining examples 1.1 & 1.3
• (41.6875)10 = (101001.1011)2
• Combining examples 1.2 & 1.4
• (153.513)10 = (231.406517…)8
• How to convert (16)8 to binary?
• How to convert (12)16 to binary?
18

1.4 Octal and Hexadecimal


Numbers
• The conversion from and to binary, octal and hexadecimal
plays important role in digital computers, because shorter
patterns of hex characters are easier to recognize than
long patterns of 1’s and 0’s.

• Since 23=8 and 24=16, each octal digit corresponds to


three binary digits and each hexadecimal digit
corresponds to four binary digits, thus we can convert
without going through decimal phase.
19

1.4 Octal and Hexadecimal


Numbers Decimal
(Base-10)
Binary
(Base-2)
Octal
(Base-8)
Hexadecimal
(Base-16)
• Table 1.2 0 0000 00 0
1 0001 01 1
2 0010 02 2
3 0011 03 3
4 0100 04 4
5 0101 05 5
6 0110 06 6
7 0111 07 7
8 1000 10 8
9 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
20

1.4 Octal and Hexadecimal


Numbers
• To convert from binary into octal, form groups of 3 starting
from right to left for integer part and left to right for the
fraction part and then assign each group an octal digit e.g.
(10110001101011.11110000011)2=(?)8
010110001101011.11110000010
( 12 6 1 5 3 . 7 4 0 6 )8

Binary 000 001 010 011 100 101 110 111


Octal 0 1 2 3 4 5 6 7
21

1.4 Octal and Hexadecimal


Numbers
• To convert from binary into hexadecimal, form groups of 4
starting from right to left for integer part and left to right for
the fraction part and then assign each group a
hexadecimal digit e.g.
(10110001101011.11110000011)2=(?)16
0010110001101011.11110000010
( 1
2 C 6 B . F 0 6 )16

Binary 0000 0001 0010 0011 0100 0101 0110 0111


Hexa-D 0 1 2 3 4 5 6 7
Binary 1000 1001 1010 1011 1100 1101 1110 1111
Hexa-D 8 9 A B C D E F
22

1.4 Octal and Hexadecimal


Numbers
• To convert from octal and hexadecimal numbers to binary,
reverse the procedure. Replace an octal digit by it’s 3 bit
binary code and a hexadecimal digit by it’s 4 bit binary
code. e.g. (673.124)8=(?)2
• 6=110, 7=111, 3=011 and so on. Thus,
• (673.124)8 = (110 111 011 . 001 010 100)2 =
(110111011.0010101)2 .
• We may discard the zeros at the left most integer portion
and right most fraction portion.
• (306.D)16 = (0011 0000 0110 . 1101)2 =
(1100000110.1101)2
23

1.4 Octal and Hexadecimal


Numbers
• Binary numbers are difficult to work with because they
require 3 to 4 times as many digits as their decimal
equivalent.

• Since digital computers use binary numbers it becomes


necessary for human operators or user to communicate
directly with machine by means of such numbers.

• But humans may use octal or hexadecimal to interpret


binary systems. By doing this humans use less numbers
and are still able to understand the machine which uses
binary code.
24

1.4 Octal and Hexadecimal


Numbers
• By this method, user thinks in terms of octal or
hexadecimal numbers and performs the required
conversion by inspection when direct communication with
machine is necessary.

• During communication between people, octal or


hexadecimal representation is more desirable because of
less digits used for same binary data.

• Thus most computer manuals use either octal or


hexadecimal numbers to specify binary quantities.
Hexadecimal tends to win-out, since it represents a byte
with two digits.
25

Message for end of every


lecture:
Solve end of chapter
problems (Keeping a
manual won’t be enough)
26

1.5 Complements of Numbers


• Complements are used in digital computers to simplify the
subtraction operation and for logical manipulation.

• Simplifying operation leads to simpler, less expensive


circuits to implement the operations.

• There are two types of complement (C) for each base-r


system, the radix complement referred to as r’s
complement, and the diminished-radix complement
referred to as (r-1)’s complement. r ≡ radix

• For binary, i.e. base 2 system, r=2, 2’s complement and


1’s complement exist, for decimal 10’s C and 9’s C exist.
27

1.5 Complements (Diminished


Radix)
• Suppose, we have a number N in base-r which has n
digits, (r-1)’s complement of N is defined as (rn – 1) – N

• *Remember, N is supposed to be in base-r, rn is in base-r


and the subtraction rules are to be as in base-r.

• i.e. for base-2 i.e. binary, N would only have 1’s and 0’s,
2n will be written in binary which always will be 1 followed
by n zeroes (this is true for any base), and finally the
operation (rn – 1) – N is to be binary subtraction.

• rn – 1 is n ones in base-2, n nines in base-10, n sevens in


base-8, n F’s in base-16.
28

1.5 Complements (Diminished


Radix)
• For base 10,10n is 1 followed by n zeroes, e.g. 104 = 10000.
Thus 104 – 1 = 10000 - 1 = 9999 i.e. 4 9’s.

• Thus. 9’s complement will be obtained by subtracting each


digit from 9.

• The 9’s complement of 546700? (rn – 1) – 546700. N=546700,


r=?, n=?

• N=546700, r=10, n=6, Thus 9’s C of N is (106-1)-546700,


(1000000-1)-546700 = 999999-546700 = 453299

• Similarly 9’s C of 012398 is going to be …


• 987601
29

1.5 Complements (Diminished


Radix)
• For base 2,2n in base-2 is 1 followed by n zeroes, e.g. 24 =
10000. Thus 24 – 1 = 10000 - 1 in base 2 is 1111 i.e. 4 1’s.

• Thus. 1’s complement of a binary number will be obtained by


subtracting each digit from 1 in base-2.

• When subtracting from 1,we can either have 1-0=1 or 1-1=0,


which causes the bit to change from 0 to 1 or 1 to 0
respectively.

• Therefore 1’s C of a binary number is taken by simply


complementing each binary digit / bit. (no need for subtraction)

• 1’s C of 1011000 is 0100111 & 1’s C of 0101101 is


• 1010010
*Octal / Hexadecimal ?
30

1.5 Complements (Radix C)


• r’s complement of an n-digit number N in base-r is defined
as rn-N for N≠0 and 0 for N=0

• r’s C can also be taken by adding 1 to (r-1)’s C. Note that


(r-1)’s C is (rn-1)-N. Adding 1, {(rn-1)-N}+1= rn-1-N+1 =
rn-N.

• Thus, 10’s C of 2389 is 7610+1=7611

• And 2’s C of 1011100 is 010011+1 = 010100


31

1.5 Complements (Radix C(Shortcut


method))
• To obtain 10’s C of a decimal number, leave all least
significant zeroes unchanged, subtracting the first
non-zero least significant digit from 10 and subtracting all
higher significant digits from 9.

9 9 9 9 9 10
• Thus, 10’s C of 012398 is
• 987602

9 9 9 10
• And 10’s C of 246700 is
• 753300
32

1.5 Complements (Radix C(Shortcut


method))
• Similarly, to obtain 2’s C of a binary number, leave all
least significant zeroes and the first 1 unchanged, and
complementing all other higher significant digits.

• Thus, 2’s C of 1101100 is


• 0010100

• Similarly, 2’s C of 1111111 is


• 0000001

• And 2’s C of 0110111 is


• 1001001
33

1.5 Complements of Numbers


• In previous definition, we assumed that the numbers did
not have a radix point.

• If N has a radix point, remove the radix point temporarily.


Take the r’s or (r-1)’s C of the number and then restore
radix point at its original position.

• Also, note that the complement of the complement


restores the original number. For example, r’s C of N is
(rn-N) and C of the complement is rn-(rn-N) = rn-rn+N = N
i.e. original number.
34

1.5 Complements(Subtraction with Complements)


• Direct method taught in school uses the borrow concept
which works well with paper and pencil but with digital
hardware, the method is less efficient than the method
that use complements.
• The subtraction of two n-digit unsigned numbers M-N, in
base-r can be done as follows:
• Step1: Add M to r’s C of N, i.e. perform M+(rn-N)=M-N+rn
• Step2: (Case-I) If M≥N, the sum will produce an end carry
rn, which can be discarded, what is left is result M-N
• Step2: (Case-II) If M<N, the sum does not produce an end
carry and is equal to rn-(N-M). Take r’s C which will be
rn-[rn-(N-M)] = rn-rn+(N-M)=N-M and place a –ve sign in
front i.e. –ve (M-N)
35

1.5 Complements(Subtraction with Complements)


• Example 1.5: Using 10’s C, find the result of 72532-3250.
• Step0: Equalize the digits of both numbers i.e. 03250
• Step1: M+(rn-N)
M = 72532
n
r -N = 10’s C of N = 96750
Sum = 169282 End carry produced
S2-C1=Discard end carry= -100000→105 (Step2-Case1)
Answer = 69282
• It is the end carry that tells us that M≥ N & the result thus
will be positive. Have to discard end carry though.
36

1.5 Complements(Subtraction with Complements)


• Example 1.6: Using 10’s C, find the result of 3250-72532.
• Step0: Equalize the digits of both numbers i.e. 03250
• Step1: M+(rn-N)
M = 03250
n
r -N = 10’s C of N = 27468
Sum = 30718

• No end carry produced, thus Step2 Case-II, this means


that M<N, so the correct answer is –(10’s C of Sum) i.e
• -69282
37

1.5 Complements(Subtraction with Complements)


• Example 1.7: Given two binary numbers X=1010100 &
Y=1000011, perform the subtraction (a) X-Y using 2’s C.
• Step0: Equalize the digits of both numbers.(Already done)
• Step1: X+(rn-Y)
X = 1010100
rn-N = 2’s C of Y = 011110
1
Sum = 10010001 End carry produced
S2-C1=Discard end carry= -10000000→27 (Step2-Case1)
Answer = 0010001

• It is the end carry that tells us that X≥ Y & the result thus
will be positive. Have to discard end carry though.
38

1.5 Complements(Subtraction with Complements)


• Example 1.7: Given two binary numbers X=1010100 &
Y=1000011, perform the subtraction (b) Y-X using 2’s C.
• Step0: Equalize the digits of both numbers.(Already done)
• Step1: Y+(rn-X)
Y = 1000011
rn-N = 2’s C of X = 0101100
Sum =
1101111
• No end carry produced, thus Step2 Case-II, this means
that Y<X, so the correct answer is –(2’s C of Sum) i.e
• -0010001
39

1.5 Complements(Subtraction with Complements)


• Subtraction of numbers can also be done by means of
(r-1)’s C. Just remember (r-1)’s C is 1 less than the r’s C.
• The subtraction M-N using (r-1)’s C can be done as
follows:
• Step1: Add M to (r-1)’s C of N, i.e. perform M+[(r-1)’s C of N]
= M+(rn-1-N)
• Step2: (Case-I) If M≥N, the sum will produce an end carry
rn, discard the end carry and then add 1 to the result
•Simultaneously discarding end carry and adding 1 is called
end carry around.
• Step2: (Case-II) If M<N, the sum does not produce an end
carry. Take (r-1)’s C of sum and add –ve sign to get the
result.
40

1.5 Complements(Subtraction with Complements)


• Example 1.8: Given two binary numbers X=1010100 &
Y=1000011, perform the subtraction (a) X-Y using 1’s C.
• Step0: Equalize the digits of both numbers.(Already done)
• Step1: X+(rn-1-Y)
X = 1010100
rn-N = 1’s C of Y = 011110
0
Sum = 10010000 End carry produced
End carry around = 1 (Step2-Case1)
Answer = X0010001 With (r-1)’s C

• It is the end carry that tells us that X≥ Y & the result thus
will be positive. Perform end carry around operation.
41

1.5 Complements(Subtraction with Complements)


• Example 1.8: Given two binary numbers X=1010100 &
Y=1000011, perform the subtraction (b) Y-X using 1’s C.
• Step0: Equalize the digits of both numbers.(Already done)
• Step1: Y+(rn-1-X)
Y = 1000011
rn-N = 1’s C of X = 0101011
Sum =
1101110
• No end carry produced, thus Step2 Case-II, this means
that Y<X, so the correct answer is –(1’s C of Sum) i.e
• -0010001
42

Message for end of every


lecture:
Solve end of chapter
problems (Keeping a
manual won’t be enough)
43

1.6 Signed Binary Numbers


• In previous topic, the binary numbers studied were unsigned,
so when results were negative, we used a minus sign on the
paper to represent them, which is not possible with hardware.

• So, we define a system so that we can represent negative


numbers only using 1’s and 0’s.
• There are two systems for signed binary numbers:
• Signed-Magnitude System (S-M-S) (Convention)
• Signed-Complement System (S-C-S)
1. 2’s Complement
2. 1’s Complement

• Both signed and unsigned binary numbers are represented by


1’s and 0’s in a computer. The user pre-determine whether the
number system is signed or unsigned.
44

1.6 Signed Binary Numbers


(S-M-S)
• Signed Magnitude System uses the left-most bit to
represent the sign.

• Convention is to make the sign bit 0 for positive and 1 for


negative e.g.

Unsigned Signed (S-M-S)


01001 9 +9
11001 25 -9
45

1.6 Signed Binary Numbers


(S-C-S)
• In S-C-S, to represent the negative integer, we simply
take the 2’s C of the corresponding positive integer.

• The number of bits to represent the integer will be decided


before the implementation of the system e.g.

• If the system uses 8-bits (1 byte), then +9 is represented


as 00001001 and -9 is represented as
• 11110111 which is 2’s C of representation of +9

• Signed 1’s C can also be used for representing numbers


in S-C-S, then -9 will be represented as:
• 11110110
46

1.6 Signed Binary Numbers


• If the user already knows the system being used, there is no
confusion in identifying the number.

• Note that, the S-M-S negates a number by changing its sign


whereas S-C-S negates the number by taking its complement.

• Since +ve integers always start with ‘0’, the complement will
start with ‘1’ indicating the –ve number.

• Also note that, now we have a limitation of the highest number


we can represent by same number of bits e.g. the highest
integer that 4 bits can represent is 15, but if 4 bits are to be
used as a signed system, then +7 is the highest, since 1111
will be treated as a negative number which comes out to be -1.
47

1.6 Signed Binary Numbers


• Mostly S-C-S with 2’s C is used, since it is easier to implement
arithmetic operations with this system, as we shall see later.

• What integer/number is “11101100” in the signed 2’s C


system?

• Method1: Take 2’s C, and you will find corresponding +ve


integer i.e.
• 2’s C of 11101100 is
• 00010100, which is
• +20, so “11101100” must be -20

• Method 2: Multiply the highest power of 2 with –ve number i.e.


• 11101100= 1 x -27+1x 26+1x25+.+1x23+1x22= -128+64+32+8+4 =
-20
48

1.6 Signed Binary Numbers


Decimal S-C-S 2’s C S-C-S 1’s C S-M-S
+7 0111 0111 0111
+6 0110 0110 0110
+5 0101 0101 0101
+4 0100 0100 0100
+3 0011 0011 0011
+2 0010 0010 0010
+1 0001 0001 0001 As
evident,
+0 0000 0000 0000
It’s a 4-bit
-0 again 0000 1111 1000 system
-1 1111 1110 1001
-2 1110 1101 1010
-3 1101 1100 1011
-4 1100 1011 1100
-5 1011 1010 1101
-6 1010 1001 1110
-7 1001 1000 1111
-8 1000 - -
49

1.6 Signed Binary Numbers (Arithmetic


Addition)
• With S-M-S, the rules of decimal addition are followed i.e. If the
signs are same, we add both numbers and give result the
common sign e.g. to perform sum of +3 and +6, we will add 3
& 6 i.e. 9 and assign the common +ve sign, but to sum up -3
and -6, we will add 3 & 6 i.e. 9 but allot the common –ve sign.

• If signs are different, then the smaller number is subtracted


from the greater number and the sign of the greater number is
assigned e.g. +25+(-37) should be 37-25 with a –ve sign i.e.
-12 .

• This process requires a comparison of signs and magnitudes


and then performing either addition or subtraction.
50

1.6 Signed Binary Numbers (Arithmetic


Addition)
• The procedure for S-C-S, on the other hand, only requires
addition.
• For adding –ve numbers, just add the complements
including the sign bits. A carry out if generated will be
discarded indicating that the result is +ve
Add manually
2’s C system / 8 bit
2’s C
+6 00000110 -6 11111010
+13 00001101 2’s
C
+13 00001101
2’s C

2’s
C
+6 00000110 -6 11111010
-13 11110011 -13 11110011
*For –ve result, it’s already in 2’s C
*Discard End-carry, always form, no need to take 2’s C and give
-ve sign as in previous topic
51

Important to Note:
Difference between
addition of signed and
subtraction of unsigned
numbers
52

1.6 Signed Binary Numbers (Arithmetic


Subtraction)

• To subtract two signed binary digits when –ve numbers


are in 2’s C form, take the 2’s C of subtrahend (including
the sign bit) and add it to the minuend. Carry out if
generated is discarded. Minuend → A
Subtrahend → - B

• This is because subtraction might change into addition.


e.g. subtracting -13 from -6 produces -6-(-13) = -6 + 13=+7

• In general (±A)-(+B) changes into (±A)+(-B), because we


change subtraction into addition and, we take 2’s C of
subtrahend. Similarly, (±A)-(-B) changes into (±A) + (+B).
53

1.6 Signed Binary Numbers (Arithmetic


Subtraction)
• Consider -6-(-13)=+7. In 8-bit binary 2’s C system, this is
written as (11111010-11110011), but we change the
subtraction into addition by taking 2’s C of subtrahend. Thus
(11111010+00001101)=100000111 and by discarding end
carry, we get 00000111 which is +7 in 2’s C form.

• Note that, the addition and subtraction of S-C-S and unsigned


binary numbers is both by same rules. Thus, in computer, we
only need one common hardware circuit to handle both types
of arithmetic.

• The user or programmer must interpret the results of such


addition or subtraction differently, depending on whether it is
assumed that the numbers are signed or unsigned.
54

Message for end of every


lecture:
Solve end of chapter
problems (Keeping a
manual won’t be enough)
55

1.7 Binary Codes


• Digital systems use signals that have two distinct values and
circuit elements that have two stable states.

• Digital systems represent and manipulate not only binary


numbers, but also many other discrete elements of
information.

• To do this, discrete elements of information must be


represented by the help of binary codes i.e. (pattern of 1’s and
0’s).

• The codes must be in binary, so that they can be used with


digital systems which in today’s technology can be
manufactured economically.
56

1.7 Binary Codes


• But note that binary codes only change the symbols, and not
the meaning of the elements of information that they represent.

• Bits of a computer, most of the time, represent some type of


coded information rather than binary numbers.

• An n-bit binary code is a group of n-bits that can have 2n


distinct combination of 1’s and 0’s and each combination can
represent one element of the set being coded.

• A set of 4 elements can be coded with 2 bits, with each


element assigned one of the following combinations
00,01,10,11. Similarly, a set of 8 & 16 elements require a 3-bit
& 4-bit code respectively.
57

1.7 Binary Codes


• The bit combination of an n-bit code is determined from the
count in binary from 0 to 2n-1.

• Each element from a set can only be assigned one binary


combination and no two elements can have the same binary
combination. On the other hand, to avoid confusion, don’t
assign 2 combinations to a single element.

• Although minimum number of bits to code 2n quantities is n,


there is no maximum number of bits that may be used for a
binary code.

• For example, the 10 decimal digits can be coded with 10 bits


each having a unique combination of 9 0’s and a 1
e.g. 6 = 0001000000.
58

1.7 Binary Codes (BCD Code)


• Although the binary number system is the most natural
system for a computer, most people are more
accustomed to the decimal system.

• One way to resolve this issue is to convert decimal


numbers to binary, perform all arithmetic calculations in
binary, and then convert the binary results back to
decimal. This requires that computer stores the decimal
numbers.

• Since the computer can only accept binary numbers, so


we must represent decimal digits by means of a code that
contains 1’s and 0’s.
59

1.7 Binary Codes (BCD Code)


• On the other hand, it is also possible to perform the arithmetic
operations directly on decimal numbers when they are stored
in the computer in the coded form.

• This way user and computer can directly communicate without


the need of conversion.

• The decimal digits are 10 in total i.e. from 0 to 9. They can be


represented by >3 bits. We will use 4 bits for BCD.

• Since 10 is less than 24=16, the coding will leave some


unassigned digits. If elements of a set is not a multiple power
of 2, this will happen. Hence 6 combinations out of 16 will
remain unassigned.
60

1.7 Binary Codes (BCD Code)


• Different binary codes can be obtained by arranging 4 bits
into 10 distinct combinations/patterns. However, the code
most commonly used for decimal digits is straight binary
assignment/conversion.
Decimal Symbol BCD Digit (Coded)
0 0000
1 0001
Unused /Invalid
2 0010 Combinations
3 0011 1010
4 0100 1011
5 0101 1100
6 0110 1101
7 0111 1110
8 1000 1111
9 1001
61

1.7 Binary Codes (BCD Code)


• The scheme in table on previous slide is called binary-coded
decimal and is commonly referred to as BCD.

• Other decimal codes are possible and are presented later in


the section.

• Table gives four-bit code of or one decimal digit.

• In BCD, a number with K decimal digits requires 4 K bits e.g.


396 will be represented as 0011 1001 0110 in BCD.

• A decimal number in BCD is the same as its equivalent binary


number only when its between 0 & 9.
62

1.7 Binary Codes (BCD Code)


• A BCD number, greater than 10 looks different from its
equivalent binary number even though both are
represented by 1’s and 0’s.

• Binary combinations from 1010 to 1111 are not used and


has no meaning in BCD.

• It is important to realize that BCD numbers are decimal


numbers and not binary numbers although bits are used
to represent BCD numbers.
63

1.7 Binary Codes (BCD Code)


• The only difference between a decimal number and BCD
is that decimals are written with symbols 0,1,2,…,9 and
BCD numbers use the binary code 0000, 0001, 0010,
…,1001. The decimal value is exactly the same. Let’s
compare: Decimal Binary BCD
(10)10 (1010)2 (0001 0000)BCD
(15)10 (1111)2 (0001 0101)BCD
(165)10 (10100101)2 (0001 0110 0101)BCD
• BCD needs 12 bits and binary only 8 to encode the
decimal 165. Obviously BCD representations require
more digits. But since computer input and output data are
generated by people who use the decimal system, BCD
representation is more advantageous.
64

1.7 Binary Codes (BCD Addition)


• Consider the addition of two decimal digits in BCD, with a
carry from a previous addition. The sum cannot be greater
than 9+9+1=19.

• In binary, the range of result will be from 0000 to 10011,


but in BCD the range will be from 0000 to 0001 1001.

• In BCD addition, the numbers being added are in binary,


so there is a chance that the result may be greater than 9
which will be invalid during BCD representation.
65

1.7 Binary Codes (BCD Addition)


• Whenever the result is less than or equal to 9, the result is
a valid BCD digit and if result is greater than or equal to
10(i.e. 1010), the result is an invalid BCD digit. Adding
binary 6=(0110)2/BCD to the sum will produce correct digit.

• We also add binary 6= (0110)2 if result has a carry.


4 0100 4 0100 9 1001
5 0101 8 1000 Carry 8 1000
9 1001 12 1100 10001
011 Invalid BCD 011
0
1 0010 10
(0001 0010)BCD =(12)10 0111
(0001 0111)BCD
Valid BCD =(17)
66

1.7 Binary Codes (BCD Addition)


• Example: Using unsigned BCD addition procedure, add
984 to 576.
984
576

Add manually And Remember: Invalid BCD or Carry


67

1.7 Binary Codes (Decimal


Arithmetic)
• Like binary, BCD too has the representation and
arithmetic for signed numbers.

• For S-M-S, a 4-bit code for sign must be included.


Positive sign is designated by 0000 and –ve by 1001 (9).
• +12 = 0000 0001 0010
• -12 = 1001 0001 0010
• During addition, sign bits must be added.
• For S-C-S, either 9’s or 10’s C is used, but 10’s C is
mostly used and sign-bits are also added. Sign-bits must
always be 0 or 9, both in 10’s or 9’s C case e.g.
• (+375 + (-240)) = +135, and in BCD…
68
Decimal Digit BCD 2421-code Excess-3 8,4,-2,-1 code
Weights 8 4 2 1 2 4 2 1 BCD(bin)+3 8 4 -2 -1
1.7 0Binary Codes (Other Decimal
0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0
Codes)
1 0 0 0 1 0 0 0 1 0 1 0 0 0 1 1 1
2 0 0 1 0 0 0 1 0 0 1 0 1 0 1 1 0
3 0 0 1 1 0 0 1 1 0 1 1 0 0 1 0 1
4 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0 0
5 0 1 0 1 1 0 1 1 1 0 0 0 1 0 1 1
6 0 1 1 0 1 1 0 0 1 0 0 1 1 0 1 0
7 0 1 1 1 1 1 0 1 1 0 1 0 1 0 0 1
8 1 0 0 0 1 1 1 0 1 0 1 1 1 0 0 0
9 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1
1 0 1 0 0 1 0 1 0 0 0 0 0 0 0 1
1 0 1 1 0 1 1 0 0 0 0 1 0 0 1 0
Unused 1 1 0 0 0 1 1 1 0 0 1 0 0 0 1 1
Bit 1 1 0 1 1 0 0 0 1 1 0 1 1 1 0 0
combinations 1 1 1 0 1 0 0 1 1 1 1 0 1 1 0 1
1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 0
69

1.7 Binary Codes (Other Decimal


Codes)
• Binary codes for decimal digits require a minimum of four
bits per digit which can be arranged in a number of
different combinations, as we saw in previous slide.
• BCD (8421) & 2421 are weighted codes. Excess-3 is
corresponding binary value plus 3. 8,4,-2,-1 has both +ve
and –ve weights. (Information encoding)
• Excess-3 and 2421 are self-complementing codes i.e. 9’s
C of a number in this representation can be taken directly
by taking 1’s C of binary representation. e.g.
• Decimal: 395→9’s C→604
• Excess-3: 395→0110 1100 1000→1’s C→ 1001 0011 0111 → 604
• 2421: 395→0011 1111 1011→1’s C→1100 0000 0100 → 604
70

1.7 Binary Codes (Gray Code)


Decimal Digit Gray Code
0 0000
• The characteristic of gray code is 1 0001
that from changing one decimal to 2 0011
its successive number, its binary 3 0010
representation only changes by 4 0110
one bit. (XOR application) 5 0111
6 0101
• It helps us mostly where the 7 0100
numbers are used in normal 8 1100
sequence e.g. counters. 9 1101
10 1111
11 1110
• Going from 0111 to 1000, if LSB
12 1010
gets read before change, then
13 1011
1001 is read instead of 1000.
14 1001
15 1000
71

1.7 Binary Codes (ASCII Code)


1
2
72

1.7 Binary Codes (Error detecting codes)


• Error detecting codes are normally used when binary data
is being transferred and the distance is long enough that it
has a chance of corrupting the binary data.

• If the distance is short enough that it has the chance of


corrupting only one-bit, the parity-bit is enough to tell that
data has been corrupted. (Chapter-3: Parity detection cct)
8-bits

Character 7-bit ASCII Even Parity Odd Parity


A 1000001 01000001 11000001
a 1100001 11100001 01100001
T 1010100 11010100 01010100
73

Message for end of every


lecture:
Solve end of chapter
problems (Keeping a
manual won’t be enough)
74

Topic 1.8
Not included
75

1.9 Binary Logic


• Binary logic deals with the variables that take on two
discrete values and with operations that assume logical
meaning.

• Discrete values are dealt as 1 or 0.

• Binary logic consists of binary variables and a set of


logical operations.

• Variables are designated by letters of the alphabet, such


as A, B, C, x, y, z e.t.c. with each having only two possible
values: 1 & 0.
76

1.9 Binary Logic (Logical


Operators)

77

1.9 Binary Logic (Truth Tables)


• A Truth Table lists the result for all the possible
combinations of an input for a digital logic circuit.
AND OR NOT
Inputs Output
x y z x y z x z
0 0 0 0 0 0 0 1
0 1 0 0 1 1 1 0
1 0 0 1 0 1
1 1 1 1 1 1

z=x.y z=x+y z=x’


78

1.9 Binary Logic (Gate Symbols)


• Logic Gates are electronic devices (ICs) to perform binary
logical operations. 1 & 0 are represented by voltage levels
e.g. 0V & 5V
Symbols for Logic Gates

• Gates can have more than two inputs.


79

1.9 Binary Logic (Timing Diagram)


• We may be able to list all the scenarios of a circuit/gate
using truth table but when we want to list the output of the
circuit as the inputs are changing with time, we use timing
diagrams. (Because, then outputs also change with time.)

x-axis: time
y-axis: logic/voltage
80

Read 1.7 & 1.9 thoroughly


from book.

Solve end of chapter


problems for practice

END OF CHAPTER 1

You might also like