Вы находитесь на странице: 1из 13

Digital logic cct. Lec.

[4]

Page | 1

Binary Arithmetic
Computer circuits do not process decimal numbers; they process binary
numbers .Therefore, we are going to learn binary arithmetic. Binary
addition is the key to binary subtraction, multiplication and division. So
let us see rules for binary addition:

1- Binary Addition





Example: Add(11)
2
to (11)
2
?
Sol:

1 carry

11 3
+ 11 + 3
110 6


Example: Add (28)
10
and (15)
10
in binary?
A B Sum Carry
0 + 0 0 0
0 + 1 1 0
1 + 0 1 0
1 + 1 0 1
Digital logic cct. Lec.[4]

Page | 2

Sol:





(28)
10
=
(11100)
2

(15)
10
=(1111)
2
1 1 carry
11100 (28)
10
+
01111 (15)
10
101011 (43)
10
2- Binary Subtraction

A B Difference Borrow
0 - 0 0 0
0 - 1 1 1
1 - 0 1 0
1 - 1 0 0

2 28 0 (LSB)
2 14 0
2 7 1
2 3 1
2 1 1(MSB)
2 0
2 15 1(LSB)
2 7 1
2 3 1
2 1 1(MSB)
0
Digital logic cct. Lec.[4]

Page | 3


Example: Perform subtraction of the binary numbers (11)
2
and (01)
2
?
Sol.
11 3
- 01 - 1
10 2
3- Binary Multiplication
A B Result
0 0 0
0 1 0
1 0 0
1 1 1

It involves forming partial products, shifting each successive
partial product left one place and then adding all the partial products.
Example:
11 3
11 3
11 9
+11
1001
Digital logic cct. Lec.[4]

Page | 4

Example:
111 7
101 5
111 35
000
+111
100011
4-Binary Division
This operation follows the same procedure as division in
decimal number system.
Example: Find (62)?
Sol.




Digital logic cct. Lec.[4]

Page | 5

Complements
In digital computer s to simplify the subtraction operation and for
logical compliments are used. There are two types of complements for
each radix system diminished radix compliment. The first is referred to
as a (r)s complement and the second as the (r-1)s compliment. For
example; in binary system we substitute base value 2 in place of (r) to
refer compliment as (2s) compliment and (1s) compliment. In decimal
number system, we substitute base value 10 in place of (r) refer
compliment as (10s) compliment and (9s) compliment.
1- 1s Complement representation of Binary Numbers
The l's complement of a binary number is found by changing all 1s
to 0s and all 0s to 1s, as illustrated below:
10110010 Binary number

01001101 1s complement
Ex (1): find 1s compliment of (1101)
2
?
Sol.
1 1 0 1 number
0 0 1 0 1s compliment
Ex (2): find 1s compliment of (1011 1001)
2
?
Sol.
1 0 1 1 1 0 0 1 number
0 1 0 0 0 1 1 0 1s compliment
Digital logic cct. Lec.[4]

Page | 6

The simplest way to obtain the l's complement of a binary number


with a digital circuit is to use parallel inverters (NOT circuits), as shown
in Figure (1) below for an 8-bit binary number.

Fig. (1) Example of inverters used to obtain the 1s complement of a
binary number
2- 2s Complement representation of Binary Numbers
The 2's complement of a binary number is found by adding 1 to the
LSB of the l's complement.
2's complement = (l's complement) + 1
Ex(3): Find the 2's complement of 10110010?
Sol.
10110010 Binary number
01001101 l's complement
+ 1 add 1

01001110 2's complement
The 2's complement of a negative binary number can be realized
using inverters and an adder, as indicated in Fig.(2). This illustrates
how an 8-bit number can be converted to its 2's complement by
Digital logic cct. Lec.[4]

Page | 7

first inverting each bit (taking the l's complement) and then adding
1 to the l's complement with an adder circuit.
To convert from a l's or 2's complement back to the true
(uncomplemented) binary form, use the same two procedures
described previously. To go from the ls complement back to true
binary, reverse all the bits. To go from the 2's complement form
back to true binary, take the 1's complement of the 2's complement
number and add 1 to the least significant bit.

Fig.(2) Example of inverters and adder used to obtain the 2s
complement of a binary number



Digital logic cct. Lec.[4]

Page | 8

1s compliment subtraction

Subtraction of binary numbers can be accomplished by the direct
method by using the 1s compliment method, which allows performing
subtraction using only addition. For subtraction of two numbers we have
two cases:
Subtraction of smaller numbers from larger number.
Subtraction of larger numbers from smaller number.

Subtraction of smaller number from larger number method:
1. Determine the 1s compliment of the smaller number.
2. Add the 1s compliment to the larger number.
3. Remove the carry and add it to the result.
This is called end-around carry.
Example: Subtract (101011)
2
from (111001)
2
using 1s compliment
method?
Sol.
111001
+
010100 1s compliment of 101011
(1) 001101
+1
001110 Final answer



Digital logic cct. Lec.[4]

Page | 9

Subtraction of larger number from smaller number method:


1. Determine the 1s compliment of the larger number.
2. Add the 1s compliment to the smaller number.
3. Answer is in 1s compliment form. To get the answer in true
form take the 1s compliment and assign negative sign to the
answer.
Example: Subtract (111001)
2
from (101011)
2
using 1s compliment
method?
Sol.
101011
+
000110 1s compliment of 111001

110001 answer in 1s compliment form
-001110 answer in true form

2s compliment subtraction
Like 1s compliment subtraction in 2s compliment subtraction,
the subtraction is accomplished by only addition. For subtraction of two
numbers we have two cases:
Subtraction of smaller numbers from larger number:
1. Determine the 2s compliment of the smaller number.
2. Add the 2s compliment to the larger number.
3. Discard the carry.


Digital logic cct. Lec.[4]

Page | 10

Example: Subtract (101011)


2
from (111001)
2
using 2s compliment
method?
Sol.
111001
+
010101 2s compliment of 101011
discard (1) 001110
001110 Final answer
Subtraction of larger number from smaller number method:
4. Determine the 2s compliment of the larger number.
5. Add the 2s compliment to the smaller number.
6. Answer is in 2s compliment form. To get the answer in true
form take the 2s compliment and assign negative sign to the
answer.
Example: Subtract (111001)
2
from (101011)
2
using 1s compliment
method?
Sol.
101011
+
000111 2s compliment of 111001

110010 answer in 2s compliment form
- 001110 answer in true form


Digital logic cct. Lec.[4]

Page | 11

Signed Numbers
Digital systems, such as the computer, must be able to
handle both positive and negative numbers. A signed binary number
consists of both sign and magnitude information. The sign indicates
whether a number is positive or negative, and the magnitude is the value
of the number. There are three forms in which signed integer (whole)
numbers can be represented in binary: sign-magnitude, l's
complement, and 2' complement. Of these, the 2's complement is the
most important and the sign-magnitude is the least used.
The Sign Bit
The left-most bit in a signed binary number is the sign bit, which
tells you whether the number is positive or negative. A 0 sign bit
indicates a positive number, and a 1 sign bit indicates a negative
number.
A 0 sign bit indicates a positive number, and a 1 sign bit
indicates a negative number.
B
7
B
6
B
5
B
4
B
3
B
2
B
1
B
0

Sign Magnitude
Sign-Magnitude Form
When a signed binary number is represented in sign-magnitude,
the left-most bit is the sign bit and the remaining bits are the
magnitude bits. The magnitude bits are in true (uncomplemented)
binary for both positive and negative numbers. For example, the
decimal number +25 is expressed as an 8-bit signed binary number
using the sign-magnitude form as 00011001.
Digital logic cct. Lec.[4]

Page | 12

The decimal number - 25 is expressed as 1001100l. Notice that the


only difference between +25 and - 25 is the sign bit because the
magnitude bits are in true binary for both positive and negative numbers.
In the sign-magnitude form, a negative number has the same
magnitude bits as the corresponding positive number but the sign
bit is a 1 rather than a zero.

1' s Complement Form
Positive numbers in 1's complement form are represented the same
way as the positive sign-magnitude numbers. Negative numbers,
however, are the l's complements of the corresponding positive numbers.
For example; using eight bits the decimal number -25 is expressed
as the 1' s complement of + 25 (00011001 ) as 11100110.
In the 1's complement form, a negative number is the 1's
complement of the corresponding positive number.

2 ' s Complement Form
Positive numbers in 2's complement form are represented the same
way as in the sign-magnitude and ls complement forms. Negative
numbers are the 2's complements of the corresponding positive numbers.
Again, using eight bits, let's take decimal number -25 and express it
as the 2's complement of +25
(00011001) =11100111

In the 2s complement form, a negative number is the 2s
complement of the corresponding positive number.
Example:
Express the decimal number - 39 as an 8-bit number in the sign-
magnitude, 1's complement, and 2's complement forms.
Digital logic cct. Lec.[4]

Page | 13

Solution:
First, write the 8-bit number for +39 is (00100111)
2

In the sign-magnitude form, -39 is produced by changing the sign
bit to a 1 and leaving the magnitude bits as they are. The number is
10100111
In the 1s complement form, -39 is produced by taking the ls
complement of +39 (00100111).
11011000
In the 2's complement form, -39 is produced by taking the 2's
complement of +39 (00100111) as follows:

11011000 1's complement
+ 1
11011001 2's complement