0% found this document useful (0 votes)
162 views21 pages

Binary Arithmetic Operations Guide

Binary addition and subtraction follow specific rules. For addition, binary digits are added and a carry is generated if the sum is 2 or more. For subtraction, the subtrahend's bits are inverted and 1 is added, then the numbers are added. Signed binary uses the most significant bit as the sign bit and stores negative numbers in 2's complement form. Addition and subtraction of signed numbers follow the same rules as unsigned but discard carries to preserve the sign of the result. Overflow occurs if the result exceeds the number of bits.

Uploaded by

Shehu Abdullahi
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)
162 views21 pages

Binary Arithmetic Operations Guide

Binary addition and subtraction follow specific rules. For addition, binary digits are added and a carry is generated if the sum is 2 or more. For subtraction, the subtrahend's bits are inverted and 1 is added, then the numbers are added. Signed binary uses the most significant bit as the sign bit and stores negative numbers in 2's complement form. Addition and subtraction of signed numbers follow the same rules as unsigned but discard carries to preserve the sign of the result. Overflow occurs if the result exceeds the number of bits.

Uploaded by

Shehu Abdullahi
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/ 21

Binary Addition

The rules for binary addition are


0 + 0 = 0 Sum = 0, carry = 0
0 + 1 = 0 Sum = 1, carry = 0
1 + 0 = 0 Sum = 1, carry = 0
1 + 1 = 10 Sum = 0, carry = 1
When an input carry = 1 due to a previous result, the rules are

1 + 0 + 0 = 01 Sum = 1, carry = 0
1 + 0 + 1 = 10 Sum = 0, carry = 1
1 + 1 + 0 = 10 Sum = 0, carry = 1
1 + 1 + 1 = 11 Sum = 1, carry = 1

1
Binary Addition

Add the binary numbers 00111 and 10101 and show the equivalent
decimal addition.

0111
00111 7
10101 21

1 1 1 0 0 = 28

2
Binary Subtraction

The rules for binary subtraction are


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

Subtract the binary number 00111 from 10101 and show the
equivalent decimal subtraction.

1 1 1
10101
/ / / 21
00111 7
0 1 1 1 0 = 14

3
1’s Complement

The 1’s complement of a binary number is just the inverse of the digits. To
form the 1’s complement, change all 0’s to 1’s and all 1’s to 0’s.

For example, the 1’s complement of 11001010 is


00110101

In digital circuits, the 1’s complement is formed by using inverters:

1 1 0 0 1 0 1 0

0 0 1 1 0 1 0 1

4
2’s Complement

The 2’s complement of a binary number is found by adding 1 to the LSB of


the 1’s complement.

Recall that the 1’s complement of 11001010 is


00110101 (1’s complement)
To form the 2’s complement, add 1: +1
00110110 (2’s complement)
1 1 0 0 1 0 1 0

0 0 1 1 0 1 0 1
Input bits
Carry
Adder
in (add 1)
Output bits (sum)

0 0 1 1 0 1 1 0

5
Signed Binary Numbers

There are several ways to represent signed binary numbers. In all cases, the
MSB in a signed number is the sign bit, that tells you if the number is positive
or negative.

Computers use a modified 2’s complement for signed numbers.


Positive numbers are stored in true form (with a 0 for the sign bit) and negative
numbers are stored in complement form (with a 1 for the sign bit).

For example, the positive number 58 is written using 8-bits


as 00111010 (true form).

Sign bit Magnitude bits

6
Signed Binary Numbers

Negative numbers are written as the 2’s complement of the corresponding


positive number.

The negative number -58 is written as:


-58 = 11000110 (complement form)
Sign bit Magnitude bits
An easy way to read a signed number that uses this notation is to
assign the sign bit a column weight of -128 (for an 8-bit number).
Then add the column weights for the 1’s.
Assuming that the sign bit = -128, show that 11000110 = -58
as a 2’s complement signed number:
Column weights: -128 64 32 16 8 4 2 1.
1 1 0 0 0 1 1 0
-128 +64 +4 +2 = -58

7
Arithmetic Operations with Signed Numbers

Using the signed number notation with negative numbers in 2’s


complement form simplifies addition and subtraction of signed numbers.

Rules for addition: Add the two signed numbers. Discard any final carries. The
result is in signed form.
Examples:

00011110 = +30 00001110 = +14 11111111 = -1


00001111 = +15 11101111 = -17 11111000 = -8
00101101 = +45 11111101 = -3 1 11110111 = -9
Discard carry

8
Arithmetic Operations with Signed Numbers

Note that if the number of bits required for the answer is exceeded,
overflow will occur. This occurs only if both numbers have the same sign.
The overflow will be indicated by an incorrect sign bit.

Two examples are:

01000000 = +128 10000001 = -127


01000001 = +129 10000001 = -127
10000001 = -126 Discard carry 100000010 = +2

Wrong! The answer is incorrect


and the sign bit has changed.

9
Arithmetic Operations with Signed Numbers

Rules for subtraction: 2’s complement the subtrahend and add the numbers.
Discard any final carries. The result is in signed form.

Repeat the examples done previously, but subtract:

00011110 (+30) 00001110 (+14) 11111111 (-1)


- 00001111 –(+15) - 11101111 –(-17) - 11111000 –(-8)

2’s complement subtrahend and add:


00011110 = +30 00001110 = +14 11111111 = -1
11110001 = -15 00010001 = +17 00001000 = +8
1 00001111 = +15 00011111 = +31 1 00000111 = +7
Discard carry Discard carry

10
Complements of Binary Numbers

• 1’s complement
• Change all 1s to 0s and all 0s to 1s
1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1

11
Complements of Binary Numbers
• 2’s complement
• Find 1’s complement and then add 1

1 0 1 0 1 0 1 0
1

1’s complement 0 1 0 1 0 1 0 1
Input bits
Adder Carry
Output bits (sum) In (add 1)

2’s complement 0 1 0 1 0 1 1 0
12
Arithmetic Operations with Signed
Numbers

Addition of Signed Numbers


• The parts of an addition function are:
– Augend - The first number
– Addend - The second number
– Sum - The result
Numbers are always added two at a time.

13
Arithmetic Operations with Signed
Numbers
Four conditions for adding numbers:
1. Both numbers are positive.
2. A positive number that is larger than a
negative number.
3. A negative number that is larger than a
positive number.
4. Both numbers are negative.

14
Arithmetic Operations with Signed
Numbers
Signs for Addition
• When both numbers are positive, the sum is
positive.
• When the larger number is positive and the
smaller is negative, the sum is positive. The
carry is discarded.

15
Arithmetic Operations with Signed
Numbers
Signs for Addition
• When the larger number is negative and the
smaller is positive, the sum is negative (2’s
complement form).
• When both numbers are negative, the sum
is negative (2’s complement form). The
carry bit is discarded.

16
Examples (8 bit numbers)
• Add 7 and 4 (both positive) 00000111 7
+00000100 + 4
00001011 11

• Add 15 and -6 (positive > negative) 00001111 15


+11111010 + -6
Discard carry 1 00001001 9

• Add 16 and -24 (negative > positive) 00010000 16


+11101000 + -24
Sign bit is negative so negative 11111000 -8
number in 2’s complement form

• Add -5 and -9 (both negative) 11111011 -5


+11110111 + -9
Discard carry 1 11110010 -14
17
Overflow
• Overflow occurs when number of bits in sum
exceeds number of bits in addend or augend.
• Overflow is indicated by the wrong sign.
• Occurs only when both numbers are positive
or both numbers are negative

01111101 126
+ 00111010 + 58
_________ ____
10110111 183

Sign Incorrect
Magnitude Incorrect
18
Arithmetic Operations with Signed
Numbers
Subtraction of Signed Numbers
• The parts of a subtraction function are:
– Minuend - The first number
– Subtrahend - The second number
– Difference - The result
Subtraction is addition with the sign of the
subtrahend changed.

19
Arithmetic Operations with Signed
Numbers
Subtraction
• The sign of a positive or negative binary
number is changed by taking its 2’s
complement
• To subtract two signed numbers, take the
2’s complement of the subtrahend and add.
Discard any final carry bit.

20
Subtraction Examples
• Find 8 minus 3. 00001000 8 Minuend
+11111101 - 3 Subtrahend
Discard carry 1 00000101 5 Difference

• Find 12 minus -9. 00001100 12


+00001001 - -9
00010101 21

• Find -25 minus 19. 11100111 -25


+11101101 - 19
Discard carry 1 11010100 -44

• Find -120 minus -30. 10001000 -120


+00011110 - -30
10100110 -90

21

You might also like