0% found this document useful (0 votes)
5 views

Digital lecture 2

Uploaded by

a7madsala7ussain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Digital lecture 2

Uploaded by

a7madsala7ussain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Prepared by: Dana S.

Abdullah Digital 2nd Lecture

1-Arithmetic Operation:
Binary arithmetic is much simpler than decimal arithmetic because here
only two digits 0&1 are involved. Arithmetic operations in a computer are
done in its arithmetic unit by using binary numbers. The basic arithmetic
operations are, addition, subtraction, multiplication, division.
These operations are performed by digital logic circuits called the adder,
subtractor, multiplier and divider.
The arithmetic rules for Addition, Subtraction, Multiplication, and
Division of binary numbers are given below:
1-1 Binary Addition: The four basic rules for adding binary digits (bits) are
as follows.
0+0=0 Sum of 0 with a carry 0
0+1=1 Sum of 1 with a carry 0
1+0=1 Sum of 1 with a carry 0
1+1=1 0 Sum of 0 with a carry 1

Ex1: 110 Ex2: 111


+100 + 011
1010 1010

Ex3: 1111
+1100
11011

1-2 Binary Subtraction: The four basic rules for subtracting are as
follows.
0-0=0
1-1=0
1-0=1
1
Prepared by: Dana S. Abdullah Digital 2nd Lecture

0-1=1 0-1 with a borrow of 1

Ex1: 11 Ex2: 110


-01 -101
10 001

Ex3: 101101
-001110
011111

1-3 Binary Multiplication & Division: We follow the same rule of decimal
numbers.

2-Complement Representations:
2-1: 1’s complement and 2’s complement:

There are two complement forms used in digital systems to represent


signed numbers. These are 1’s complement and 2’s complement form. These
two forms are used to represent negative numbers. Most digital computers
do subtraction by the 2’s complement method .The advantage of performing
subtraction by the complement method is reduction in the hardware. Instead
of having separate digital circuits for addition and subtraction, only adding
circuits are needed .i.e. subtraction is also performed by adders only.
To take the 1’s complement of a binary number, simply change all 1’s to 0s
and all 0’s to 1s.
For Example
The 1’s complement of 110010 is 001101
Similarly the 2’s complement of a binary number can be obtained by adding
1 to its 1’s complement

2
Prepared by: Dana S. Abdullah Digital 2nd Lecture

For Example
Find the 2’s complement of 10110
1’s complement of 10110= 01001
For obtaining 2’s complement of 10110, you have to add 1 to 01001(1’s
complement of 10110)
i.e, 1+ 01001= 01010

2-1-1:Subtraction using 1’s complement :


The subtraction using 1’s complement can be obtained by the following
methods:
• Take the 1’s complement of the subtrahend.

• Add this to the minuend.

• If a carry is generated, it indicates that the answer is positive. Add the


carry to the result.

• If no carry is generated, then the answer is negative. Take the 1’s


complement of the original addition and change the sign.

Ex1: Subtract (1011)2 from (1110)2 using 1’s complement method.


Solution:

The answer is (0011)2

3
Prepared by: Dana S. Abdullah Digital 2nd Lecture

Ex2: Subtract (11000)2 from (101)2 using 1’s complement method

Solution:

The answer is –ve, since no carry is obtained. Then the answer is the 1’s
complement of the 01100 and is in opposite sign i.e, -10011

2-1-2: Subtraction using 2’s complement:


2’s complement subtraction can be obtained by the following methods.
• Take the 2’s complement of the subtrahend.
• Add it to the minuend.
• Presence of a Carry indicates that the answer is positive. Omit the
carry.
• Absence of a carry indicates that the answer is negative. Take the 2’s
complement of the original addition and change the sign.
Ex1: Subtract (1011)2 from (1110)2 using 2’s complement method
Solution:

The carry is ignored. Thus the answer is (0011)2

Ex2: Subtract (1010)2 from (1000)2 using 2’s complement method

4
Prepared by: Dana S. Abdullah Digital 2nd Lecture

Solution:

No carry is obtained. The answer is the 2’s complement of (1110)2 and is in


opposite sign. i.e, -(0010)2

2-2: 9’s complement and 10’s complement:

The 9’s complement of a decimal number can be obtained by subtracting


each digit in the number from 9,i.e. a digit plus its 9’s complement equals to
9. The 9’s complement of decimal digits 0 to 9 are listed below:
Decimal Number 9’s complement
0 9
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
9 0

Ex1:
Find the 9’scomplement of each of the following decimal numbers.
a) 15 b)135
Solution: Subtract each digit in the number from 9 to get the 9’s
complement
a) 99 – 15 = 84 (9’s complement of 15)
b) 999 – 135 = 864 (9’s complement of 135)

5
Prepared by: Dana S. Abdullah Digital 2nd Lecture

But the 10’s complement of a decimal no. is equal to its 9’s complement + 1.
Ex2:
Convert the following decimal number into its 10’s complement form
a) 18 b) 152
Solution:
a) 99-18= 81 (9’s complement of 18)
81+1= 82(10’s complement of 18)
b) 999-152= 847 (9’s complement of 152)
847+1 = 848 (10’s complement of 152)
2.2.1: Subtraction using 9’s complement
Subtraction of a smaller number from a larger number using 9’s complement
Steps:
• Take the 9’s complement of the subtrahend

• Add the 9’s complement to the minuend

• Carry indicates that the answer is positive. Add the carry to the list
significant digit

• If there is no carry the answer is negative. Take the 9’s complement of


the result and change the sign

Ex1: Subtract 143 from 363 using 9’s complement


Solution:
Direct subtraction 9’s complement subtraction

6
Prepared by: Dana S. Abdullah Digital 2nd Lecture

The answer is positive. i.e, 220

Ex2: Subtract 745 from 245 using 9’s complement


Solution:
Direct subtraction 9’s complement subtraction

2-2-2: Subtraction using 10’s complement


It is analogous to the often used 2’s complement method in binary
subtraction. In this method the minuend is added to the 10’s complement of
the subtrahend and the carry is ignored.

Ex1: Subtract 54 from 88 using 10’s complement method


Solution:
Direct subtraction 10’s complement subtraction

7
Prepared by: Dana S. Abdullah Digital 2nd Lecture

Ex2: Subtract 813 from 432 using 10’s complement method


Solution:
Direct subtraction 10’s complement subtraction

3- Codes
We are very comfortable with the decimal number system, but digital
systems like computers & other digital circuits process the data in the binary
format. So, various binary codes are used to represent the data.
In this section three types of codes are identified.
3-1 BCD (Binary Coded Decimal):
A Binary Coded Decimal (BCD) is one in which, decimal digits are encoded
by their natural binary equivalents-one at a time-into groups of four bits.
For example (25)10is represented by [0010 0101] using BCD code, rather
than (11001)2. It is a positional weight code. Each position of a number
represents a specific weight.
These codes are also known as 8421 code or simply BCD code. The
number 8421 indicates the binary weights of the four bits. i.e. the weights of
the first (right most) position is 20 =1, 21 =2, 22 =4, 23 =8. Replacing from
left to right, the weights are 8-4-2-1,and hence it is called 8421 code.

8
Prepared by: Dana S. Abdullah Digital 2nd Lecture

The disadvantage of BCD code is that it requires more number of bits to


code a decimal number. But the ease of conversion between the BCD code
to decimal number and vice versa is the main advantage of this code, which
makes it useful and popular code for input, output operations in digital
systems .To convert any decimal number into BCD, each decimal digit
should be replaced by the appropriate 4-bit code. The following table,
summarizes the binary and BCD codes for the decimal numbers 0 to 15.
Decimal Numbers Binary Number BCD
0 0000 0000
1 0001 0001
2 0010 0010
3 0011 0011
4 0100 0100
5 0101 0101
6 0110 0110
7 0111 0111
8 1000 1000
9 1001 1001
10 1010 00010000
11 1011 00010001
12 1100 0001 0010
13 1101 0001 0011
14 1110 0001 0100
15 1111 0001 0101

Ex1. Convert (163)10 to BCD.


Solution: 1 6 3
0001 0110 0011
Therefore, 163 in decimal = 101100011 in BCD

9
Prepared by: Dana S. Abdullah Digital 2nd Lecture

Ex2: Convert (3906)10 to BCD


Solution: 3 9 0 6
0011 1001 0000 0110

Therefore, 3906 in decimal = 11100100000110 in BCD


Homework: Convert the binary number (10001001)2 to BCD

3-2 Gray Code:


The gray code isn’t a weighted code and isn’t suitable for arithmetic
operations, but finds application in input/output devices and in some types of
analog to digital converters. Gray code is a cyclic code which has a special
property of containing two successive code words differs in one bit position
only. It is also called as the reflected code.
3-2-1 Conversion of a binary number to gray code
• Keep the first bit of the gray code is the same as the first bit of the
binary number.
• The second bit of the gray code equals to the sum of first and second
bit of the binary number. Discard the carry if it is generated from the
sum.
• The third bit of the gray cod equals to the sum of second and third bit
of the binary number and so on.

Ex1: Convert the binary (110010)2 to gray code.


Solution:

10
Prepared by: Dana S. Abdullah Digital 2nd Lecture

So, Gray code can be determined for each binary number. The
following table shows the Binary number and its Gray code for
decimal numbers.

3-2-2 Conversion from gray code to binary


Conversion of a Gray code into its binary form involves the reverse of the
procedure as given below:
• Start with the most significant bit of the Gray code number. Copy this
bit as the MSB of the binary number.
• Add the MSB of the binary number result to the next bit of the Gray
code number.
• The sum (ignoring carry) is the next bit of the binary.
• Continue adding each bit of the binary to the next Gray code bit to its
right to get the binary bit for that position.

11
Prepared by: Dana S. Abdullah Digital 2nd Lecture

Ex: Convert [1011101]G to binary


Solution:

Therefore, [1011101]G in Gray code = [1101001]2 in Binary.

3-3 Excess-3 code:


The XS-3 code is a non-weight code. This means each position within a
binary number isn’t assigned affixed value. This code is a self
complementing code. As the name indicates, XS-3 code represents a decimal
number in binary form, as a number greater than 3. An XS-3 code is
obtained by adding 3 to a decimal number, then convert it into its equivalent
BCD code.
For Example: A decimal 4 can be coded, by adding 3 into 4, in order to
obtain 7. Then 7 encoded in its equivalent 4 bit binary code 0111.
So 0111 is the XS-3 code of the decimal number 4.
Or it can also be obtained directly in another way by adding binary
equivalent of 3 to the natural BCD code of the digit.
i.e. Decimal 4 is coded as 0100+0011=0111 in XS-3 code.

Ex1: Convert (463)10 into its XS-3 code.


Solution:

12
Prepared by: Dana S. Abdullah Digital 2nd Lecture

Converting the above sum into its BCD code, we have

Hence, the XS-3 code for (463)10 is 0111 1001 0110


The following table summarizes the BCD and XS-3 code for decimal digits.
Decimal BCD XS-3
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100

13

You might also like