You are on page 1of 78

MBEYA UNIVERSITY OF SCIENCE AND

TECHNOLOGY
INSTITUTE OF SCIENCE AND TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING

CS 8235

Course Instructor: Mr. A. S. Sikoro


BINARY ARITHMETIC
Binary Addition
• The rules of binary addition
Add the binary numbers:
(a) 1010 and 1101 (b) 0110 and 1111
Binary Subtraction
The rules of binary subtraction:
The subtraction between two numbers can be performed in three
different ways:
 The direct method,
 The r’s complement method, and
 The (r – 1)’s complement method.
Subtraction Using the Direct Method
 The direct method of subtraction uses the concept of borrow.
 In this method, we borrow a 1 from a higher significant position
when the minuend digit is smaller than the corresponding
subtrahend digit.
Example 1. Using the direct method to perform the subtraction
1001 – 1000.
Example 2. Using the direct method to perform the subtraction
1000 – 1001.
 When the minuend is smaller than the subtrahend the result of
subtraction is negative and in the direct method the result obtained is in
2’s complement form. So to get back the actual result we have to
perform the 2’s complement again on the result thus obtained and
negate it.
Binary Multiplication
The rules of binary multiplication:
Multiply the following binary numbers:
(a) 0111 and 1101 and (b) 1.011 and 10.01.
Binary Division
The rules regarding binary division
Divide the following binary numbers:
(a) 11001 and 101 and (b) 11110 and 1001.
1’S AND 2’S COMPLEMENT ARITHMETIC
 Digital circuits perform binary arithmetic operations.
 It is possible to use the circuits designed for binary addition to perform
binary subtraction.
 Only we have to change the problem of subtraction into an equivalent
addition problem.
 This can be done if we make use of 1’s and 2’s complement form of the
binary numbers as we have already discussed.
Subtraction Using 1’s Complement
 Binary subtraction can be performed by adding the 1’s complement of
the subtrahend to the minuend.
 If a carry is generated, remove the carry, add it to the result.
 This carry is called the end-around carry.
 Now if the subtrahend is larger than the minuend, then no carry is
generated.
 The answer obtained is 1’s complement of the true result and opposite in
sign.
Example 1. Subtract (1001)2 from (1101)2 using the 1’s complement
method. Also subtract using the direct method and compare.
Example 2. Subtract (1100)2 from (1001)2 using the 1’s complement
method. Also subtract using the direct method and compare.
 In the direct method, whenever a larger number is subtracted from a
smaller number, the result obtained is in 2’s complement form and
opposite in sign.
 To get the true result we have to discard the carry and make the 2’s
complement of the result obtained and put a negative sign before the
result.
 In the 1’s complement subtraction, no carry is obtained and the result
obtained is in 1’s complement form.
 To get the true result we have to make the 1’s complement of the result
obtained and put a negative sign before the result.
Subtraction Using 2’s Complement
• Binary subtraction can be performed by adding the 2’s complement of
the subtrahend to the minuend. If a carry is generated, discard the carry.
• Now if the subtrahend is larger than the minuend, then no carry is
generated.
Subtraction Using 2’s Complement
• The answer obtained is in 2’s complement and is negative.
• To get a true answer take the 2’s complement of the number and change
the sign.
• The advantage of the 2’s complement method is that the end-around
carry operation present in the 1’s complement method is not present
here.
Ex.1: Subtract (0111)2 from (1101)2 using the 2’s complement method.
Also subtract using the direct method and compare.
Ex.2: Subtract (1010)2 from (1001)2 using the 2’s complement method. Also
subtract using the direct method and compare.
• In the direct method, whenever a larger number is subtracted from a
smaller number, the result obtained is in 2’s complement form and
opposite in sign.
• To get the true result we have to discard the carry and make the 2’s
complement of the result obtained and put a negative sign before the
result.
• In the 2’s complement subtraction, no carry is obtained and the result
obtained is in 2’s complement form.
• To get the true result we have to make the 2’s complement of the result
obtained and put a negative sign before the result.
SIGNED BINARY NUMBERS
 So far whatever discussions were made, there was no consideration of
sign of the numbers.
 But in real life one may have to face a situation where both positive and
negative numbers may arise.
 So we have to know how the positive and negative binary numbers may
be represented.
SIGNED BINARY NUMBERS
 Basically there are three types of representations of signed binary
numbers:-
 sign-magnitude representation
 1’s complement representation and
 2’s complement representations
Sign-magnitude Representation
• In decimal system, generally a plus (+) sign denotes a positive number
whereas a minus (–) sign denotes a negative number. But, the plus sign is
usually dropped, and no sign means the number is positive. This type of
representation of numbers is known as signed numbers.
• But in digital circuits, there is no provision to put a plus or minus sign,
since everything in digital circuits have to be represented in terms of 0
and 1.
Sign-magnitude Representation
• Normally an additional bit is used as the sign bit.
• Generally, a 0 is reserved for a positive number and a 1 is reserved for a
negative number.
• For example, an 8-bit signed binary number 01101001 represents a
positive number whose magnitude is (1101001)2 = (105)10. The MSB is 0,
which indicates that the number is positive.
Sign-magnitude Representation
• On the other hand, in the signed binary form, 11101001 represents
a negative number whose magnitude is (1101001) 2 = (105)10.
• The 1 in the MSB position indicates that the number is negative
and the other seven bits give its magnitude.
• This kind of representation of binary numbers is called sign-
magnitude representation.
Find the decimal equivalent of the following binary
numbers assuming the binary numbers have been
represented in sign-magnitude form.
(a) 0101100
(b) 101000
(c) 1111
(d) 011011
Solution:
(a) Sign bit is 0, which indicates the number is positive.
Magnitude 101100 = (44)10
Therefore (0101100)2 = (+44)10.
(b) Sign bit is 1, which indicates the number is negative.
Magnitude 01000 = (8)10
Therefore (101000)2 = (–8)10.
(c) Sign bit is 1, which indicates the number is negative.
Magnitude 111 = (7)10
Therefore (1111)2 = (–7)10.
(d) Sign bit is 0, which indicates the number is positive.
Magnitude 11011 = (27)10
Therefore (011011)2 = (+27)10.
1’s Complement Representation
• In 1’s complement representation, both numbers are a complement of
each other.
• If one of the numbers is positive, then the other will be negative with the
same magnitude and vice versa.
• For example, (0111)2 represents (+ 7)10, whereas (1000)2 represents (–
7)10 in 1’s complement representation.
• Also, in this type of representation, the MSB is 0 for positive numbers
and 1 for negative numbers.
Represent the following numbers in 1’s complement form.
(a) +5 and –5 (b) +9 and –9 (c) +15 and –15
Solution:
(a) (+5)10 = (0101) and
(–5)10 = (1010)2
(b) (+9)10 = (01001)2 and
(–9)10 = (10110)2
(c) (+15)10 = (01111)2 and
(–15)10 = (10000)2
2’s Complement Representation
• If 1 is added to 1’s complement of a binary number, the resulting
number is 2’s complement of that binary number.
• For example, (0110)2 represents (+6)10, whereas (1010)2 represents (–
6)10 in 2’s complement representation.
• Also, in this type of representation, the MSB is 0 for positive numbers
and 1 for negative numbers.
E.g. Represent the following numbers in 2’s complement form.
(a) +11 and –11 (b) +9 and –9 (c) +18 and –18
Solution.
(a) (+11)10 = (01011)2
and (–11)10 = (10101)2
(b) (+9)10 = (01001)2
and (–9)10 = (10111)2
(c) (+18)10 = (010010)2
and (–18)10 = (101110)2
Represent (–19) in
(a) Sign-magnitude,
(b) one’s complement, and
(c) two’s complement representation.
Solution.
The minimum number of bits required to represent (+19)10 in signed
number format is six.
Therefore, (+19)10 = (010011)2
Therefore, (–19)10 is represented by
(a) 110011 in sign-magnitude representation.
(b) 101100 in 1’s complement representation.
(c) 101101 in 2’s complement representation.
OCTAL ARITHMETIC

 Addition
 Subtraction
 Multiplication
 Division
7’s AND 8’s COMPLEMENT ARITHMETIC
 The 7’s complement of an octal number can be found by subtracting
each digit in the number from 7.
 8’s complement can be obtained by subtracting the LSB from 8 and
the rest of each digit in the number from 7.
 The 7’s and 8’s complement of the octal digits 0 to 7
 is shown in Table below.
Subtraction Using 7’s Complement
Ex.1: Subtract (372)8 from (453)8 using the 7’s complement method. Also
subtract using the direct method and compare.
Ex.2: Subtract (453)8 from (372)8 using the 7’s complement method. Also
subtract using the direct method and compare.
 In the direct method, whenever a larger number is
subtracted from a smaller number, the result obtained is in
8’s complement form and opposite in sign.
 To get the true result we have to discard the carry and make
the 8’s complement of the result obtained and put a negative
sign before the result.
Subtraction Using 8’s Complement
Ex.1: Subtract (256)8 from (461)8 using the 8’s complement method. Also
subtract using the direct method and co
Ex.2: Subtract (461)8 from (256)8 using the 8’s complement method. Also
subtract using the direct method and compare.
 In the direct method, whenever a larger number is subtracted
from a smaller number, the result obtained is in 8’s complement
form and opposite in sign.
 To get the true result we have to discard the carry and make the
8’s complement of the result obtained and put a negative sign
before the result.
DECIMAL ARITHMETIC

 Addition
 Subtraction
 Multiplication
 Division
9’s AND 10’s COMPLEMENT ARITHMETIC
 The 9’s complement of a decimal number can be found by
subtracting each digit in the number from 9.
 The 10’s complement can be obtained by subtracting the LSB
from 10 and the rest of each digit in the number from 9.
 The 9’s and 10’s complement of the decimal digits 0 to 9 is shown
in Table below.
• The method of subtraction using 9’s complement method is the same as
1’s complement method in a binary system.
• Here also the carry obtained is added to the result to get the true result.
• As like in the previous cases, if the minuend is larger than the
subtrahend, no carry is obtained and the result is obtained in 9’s
complement form.
• To get the true result we have to again get the 9’s complement of the
result obtained and put a negative sign before it.
• Similarly, the method of subtraction using 10’s complement method is
the same as 2’s complement method in a binary system.
• Here also the carry obtained is discarded to get the true result.
• And as in the previous cases, if the minuend is larger than the
subtrahend, no carry is obtained and the result is obtained in 10’s
complement form.
• To get the true result we have to again get the 10’s complement of the
result obtained and put a negative sign before it.
Subtraction Using 9’s Complement
Ex.1: Subtract (358)10 from (592)10 using the 9’s complement method. Also
subtract using the direct method and compare.
Ex.2: Subtract (592)10 from (358)10 using the 9’s complement method. Also
subtract using the direct method and compare.
Subtraction Using 10’s Complement
Ex.1: Subtract (438)10 from (798)10 using the 10’s complement method.
Also subtract using the direct method and compare.
Ex.2: Subtract (798)10 from (438)10 using the 10’s complement method. Also
subtract using the direct method and compare.
HEXADECIMAL ARITHMETIC

 Addition
 Subtraction
 Multiplication
 Division
15’s AND 16’s COMPLEMENT ARITHMETIC
 The 15’s complement of a hexadecimal number can be found by
subtracting each digit in the number from 15.
 The 16’s complement can be obtained by subtracting the LSB from 16
and the rest of each digit in the number from 15.
 The 15’s and 16’s complement of the hexadecimal digits 0 to F is
shown in Table below.
 The method of subtraction using 15’s complement method is the same
as 9’s complement method in a decimal system.
 Here also the carry obtained is added to the result to get the true result.
 And as in the previous cases, if the minuend is larger than the
subtrahend, no carry is obtained and the result is obtained in 15’s
complement form.
 To get the true result we have to again get the 15’s complement of the
result obtained and put a negative sign before it.
 Similarly, the method of subtraction using 16’s complement method is
the same as 10’s complement method in a decimal system.
 Here also the carry obtained is discarded to get the true result.
 And as in the previous cases, if the minuend is larger than the
 subtrahend, no carry is obtained and the result is obtained in 16’s
complement form.
 To get the true result we have to again get the 16’s complement of the
result obtained and put a negative sign before it.
Subtraction Using 15’s Complement
Ex.1: Subtract (2B1)16 from (3A2)16 using the 15’s complement method.
Also subtract using the direct method and compare.
Ex.2: Subtract (3A2)16 from (2B1)16 using the 15’s complement method. Also
subtract using the direct method and compare.
 In the direct method, whenever a larger number is subtracted from a
smaller number, the result obtained is in 16’s complement form and
opposite in sign.
 To get the true result we have to discard the carry and make the
16’s complement of the result obtained and put a negative sign
before the result.
Subtraction Using 16’s Complement
Ex.1: Subtract (1FA)16 from (2DC)16 using the 16’s complement method. Also
subtract using the direct method and compare.
Ex.2: Subtract (2DC)16 from (1FA)16 using the 16’s complement method.
Also subtract using the direct method and compare.
BCD ADDITION
• The full form of BCD is Binary Coded Decimal.
• In this code, each decimal digit from 1 to 9 is coded in 4-bit binary
numbers.
• But with 4-bit binary sixteen different groups can be obtained,
whereas we require only ten groups to write BCD code.
• The other six groups are called forbidden codes in BCD and they
are invalid for BCD.
BCD ADDITION
• BCD is a numerical code.
• Many applications require arithmetic operation.
• Addition is the most important of these because the other three
operations, viz. subtraction, multiplication, and division, can be
performed using addition.
BCD ADDITION
There are certain rules to be followed in BCD addition as given below.
1. First add the two numbers using normal rules for binary addition.
2. If the 4-bit sum is equal to or less than 9, it becomes a valid BCD
number.
BCD ADDITION
3. If the 4-bit sum is greater than 9, or if a carry-out of the group is
generated, it is an invalid result.
In such a case, add (0110)2 or (6)10 to the 4-bit sum in order to
skip the six invalid states and return the code to BCD.
If a carry results when 6 is added, add the carry to the next 4-bit
group.
Add the following BCD numbers:
(a) 0111 and 1001 and (b) 10010010 and 01011000.
BCD SUBTRACTION
In order to subtract any number from another number we have to add the
9’s complement of the subtrahend to the minuend.
Also, we can use the 10’s complement to perform the subtraction
operation.
Carry out BCD subtraction for (893) – (478) using 9’s
complement method.
Carry out BCD subtraction for (768) – ( 274) using 10’s
complement method.

You might also like