Digital Design: Subtraction of Binary Numbers and Representation of Negative Values

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Digital Design

Subtraction of Binary Numbers and


Representation of Negative Values
Introduction

1. Binary Subtraction

In case of binary addition, when 1 is added to 1, it is


equal to 0, and 1 carry forward to the next high order digit.
In case of binary subtraction, when 1 is subtracted from 0,
then we borrow 1 from next order digit and get the
remainder as 1.

0–0=0
1–0 =1
1–1 =0
0 - 1 = 1 (Borrow 1, like 2 -1)
Binary Subtraction Example

123.75 – 85.5
1 [Borrow]
123.75 1111011.11
- 85.50 1010101.10
------------- -----------------------
38.25 0100110.01
2. Some Important Binary Number Properties

Given an n-bit binary number, the following properties apply:

a. The maximum value is 2(n) -1

Example: (n=4) 1111 = 24 -1 = 16 -1 = 15

b. The place value of the Most Significant bit is 2(n-1).

Example: in 1111, the MSB has a place value of:

2(3) = 23= 8
3. One’s Complement

Given 2 n-bit binary integers x and y, x is the one’s complement of y


(and vice versa) if:

x + y = 2n -1 (or maximum value given n bits)

Example: Given x = 1010, what is the ones complement?

x = 1010 and 24 -1 = 1610-1 = 1510, then

y = 15 – x = 15 – 10 =5 or 0101

*Note: The one’s complement in binary can be computed by


flipping 0’s and 1s.
Example 2: Find the one’s complement of 123

127 1111111
- 123 1111011
------------- ------------------
4 0000100
*Note: Ones complement using decimal does not apply to
numbers with fractions.
4. Ones Complement Property of Binary Fractions:

Given an n bit binary fraction,

a. The maximum value is sum of 2-1 to 2-(n)

EXAMPLE (n=3): 0.111 = .5 +.25 + .125 = .875

b. The one’s complement of a binary fraction, is the


maximum value given the number of bits minus the fraction itself

Example: Find the one’s complement of 0.62510 (= 0.1012)

• Note: 0.111 = 0.5+0.25+0.125 = 0.875

0.875 – 0.625 =0.25 =.0102


The ones complement of Fractions can also be computed by flipping
0s and 1s.
5. Two’s Complement of Binary Number (Definition)

The 2’s complement of a binary Number is the 1’s complement +


1;

Example: The 2’s complement of 1011:

1011 Reverse: 0101


1's complement 0100 1010
+ 1 +1
----------- ---------
0101 1011
Note: The 2’s complement is the negative representation of a
binary number so that subtraction can be done by adding the
2’s complement. The same process is used to convert the
number to its original value.
6. One’s and Twos Complement Table
DECIMAL 16 8 4 2 1Binary 1'S Complement 2'S Complement
0 0 0 0 0 0 00000 11111 00000
1 0 0 0 0 1 00001 11110 11111
2 0 0 0 1 0 00010 11101 11110
3 0 0 0 1 1 00011 11100 11101
4 0 0 1 0 0 00100 11011 11100
5 0 0 1 0 1 00101 11010 11011
6 0 0 1 1 0 00110 11001 11010
7 0 0 1 1 1 00111 11000 11001
8 0 1 0 0 0 01000 10111 11000
9 0 1 0 0 1 01001 10110 10111
10 0 1 0 1 0 01010 10101 10110
11 0 1 0 1 1 01011 10100 10101
12 0 1 1 0 0 01100 10011 10100
13 0 1 1 0 1 01101 10010 10011
14 0 1 1 1 0 01110 10001 10010
15 0 1 1 1 1 01111 10000 10001
16 1 0 0 0 0 10000 01111 10000
17 1 0 0 0 1 10001 01110 01111
18 1 0 0 1 0 10010 01101 01110
19 1 0 0 1 1 10011 01100 01101
20 1 0 1 0 0 10100 01011 01100
21 1 0 1 0 1 10101 01010 01011
22 1 0 1 1 0 10110 01001 01010
23 1 0 1 1 1 10111 01000 01001
24 1 1 0 0 0 11000 00111 01000
25 1 1 0 0 1 11001 00110 00111
26 1 1 0 1 0 11010 00101 00110
27 1 1 0 1 1 11011 00100 00101
28 1 1 1 0 0 11100 00011 00100
29 1 1 1 0 1 11101 00010 00011
30 1 1 1 1 0 11110 00001 00010
31 1 1 1 1 1 11111 00000 00001

Problem: Given a decimal value representing an n bit binary


number, find the excel formula to compute 1’s and 2’s
complement.
7. The 2’s Complement of Binary Fractions

The 2’s complement of a binary fraction can be computed by


converting the integer and fractional part to 1’s complement and
adding one to the least significant bit.

Example: Find the 2’s complement of 123.7510

123.7510 = 1111011.11
1’s Complement 0 0 0 0 1 0 0 . 0 0
+.0 1
----------------------
2’s Complement 0 0 0 0 1 0 0 . 0 1

Problem: Find the Excel Formula to convert a Decimal number


with fractions (both integer and fraction) to 1’s and 2’s
complement in binary.
8. Converting an n-bit 2’s complement integer to decimal.

a. If the MSB is 1
Compute the binary sum of all with the MSB
assigned a negative place value.
b. if the MSB is 0
Extend the MSB to the next higher bit, assign it a
value of 1 and a negative place value, and compute
the binary sum of all bits.

Example: 11011 = -16 + 8 + 0 + 2 +1 = -5

01111 = 101111 = -32+0+8+4+2+1 = -17

Problem: Can this method be applied with binary fractions?

You might also like