Computer Fundamentals
Course No: CSE 141
Topic 6: Binary Arithmetic
1
Binary Addition
2
Binary Addition Example
3
Binary Subtraction
4
Binary Subtraction Example
(1) 1110 (2) 1100
− 0101 − 0101
──────── ────────
1001 0111
(3) 11000 (4) 11000
− 00001 − 01111
──────── ────────
10111 01001
5
Binary Data Representation
Data Representation
Magnitude Complement
Unsigned Signed 1’s 2’s
complement complement
6
Unsigned Magnitude
▪ It is a way to represent positive numbers using only
0s and 1s.
▪ It is a system where numbers are expressed using
only their magnitude, with no sign bit.
▪ An n-bit unsigned binary can represent numbers
from 0 to 2ⁿ - 1. For example, an 8-bit unsigned
binary can represent numbers from 0 to 255.
7
Signed Magnitude
▪ Allows both positive and negative numbers representation.
▪ In the sign bit method, the leftmost bit (MSB) is used to
represent the sign of the number. A '0' in the MSB indicates a
positive number and a '1' indicates a negative number. The
remaining bits represent the magnitude of the number in
binary form.
▪ For example, in an 8-bit signed binary system:
▪ 00000101 represents +5 in decimal (MSB is 0, so the
number is positive).
▪ 10000101 represents -5 in decimal (MSB is 1, so the
number is negative).
▪ The range of values in an n-bit system is from -(2n-1 -1) to
2n-1 - 1. 8
One's Complement
▪ In the 1's complement method, negative numbers are
represented by flipping all the bits of the corresponding
positive number.
▪ The leftmost bit (MSB) indicates the sign. A '0' in the MSB
represents a positive number and a '1' represents a negative
number.
▪ For example, in an 8-bit system:
00000101 represents +5 in decimal.
11111010 represents -5 in decimal (flip all bits of
00000101).
▪ The 1's complement method has separate representations for
+0 (00000000) and -0 (11111111), which is a problem.
9
Two's complement
▪ To find the 2's complement of a number, invert all the bits of
the binary number and add 1 to the result.
▪ The 2's complement method eliminates the need for
separate zero representations and simplifies arithmetic
operations like addition and subtraction.
▪ The range of values in an n-bit system is from
-2n-1 to (2n-1-1).
▪ It is widely used in modern processors due to its efficiency
and ease of operation.
▪ For example, in an 8-bit system:
00000101 represents +5 in decimal.
11111011 represents -5 in decimal (invert 00000101 to get
11111010, then add 1 to get 11111011). 10
Additive method of Binary
Subtraction
▪ Direct method of subtraction using the borrow concept seems
to be easiest when we perform subtraction with paper and
pencil.
▪ However, when we implement subtraction by means of digital
components, this method is less efficient than additive method
of subtraction.
▪ Additive method of subtraction is known as complementary
subtraction.
11
Example
❖Perform 12-8 using 2’s complement.
▪ Step 1: Convert to binary
12 = 00001100
8 = 00001000
▪ Step 2: Perform 2’s complement on the 8
8 = 00001000
11110111 1’s complement
+1
-8 = 11111000 2’s complement
12
Example
▪ Step 3: Add the two numbers together
12 = 00001100
-8 = 11111000
4 =1 00000100
Discard carry
13
Addition with Signed Numbers
14
Subtraction with Signed Number
15
Multiplication
There are two methods for multiplication:
▪ Direct addition – add multiplicand multiple times
equal to the multiplier, can take a long time if
multiplier is large.
▪ Partial products– Similar to long hand
multiplication. This method of partial products is
the most commonly used.
16
Multiplication
17
Multiplication
18
Division
Additive Method of Division
19
Division Example
20